String Literal对于Clob类型来说太长了

本文关键字:类型 Literal 对于 Clob String | 更新日期: 2023-09-27 18:19:15

我有一个包含clob列的表。我想保存HTML数据到(c#)。当我保存时,我得到一个错误:字符串文字太长。我存储的字符串长度是8048个字符

有谁能帮我吗?提前感谢表:创建表tablehelp(网格长)
 private string getHTML(GridView gv)
{
    StringBuilder sb = new StringBuilder();
    StringWriter textwriter = new StringWriter(sb);
    HtmlTextWriter htmlwriter = new HtmlTextWriter(textwriter);
    gv.RenderControl(htmlwriter);
    htmlwriter.Flush();
    textwriter.Flush();
    htmlwriter.Dispose();
    textwriter.Dispose();
    return sb.ToString();
}
public override void VerifyRenderingInServerForm(Control control)
{
    /* Confirms that an HtmlForm control is rendered for the specified ASP.NET
       server control at run time. */
    return;
}
protected void btnTest_Click(object sender, EventArgs e)
{
 //   string grid = getHTML(GridView1);
   TextBox7.Text = getHTML(GridView1);    
    OdbcConnection DbConnection1 = new OdbcConnection(con1);
    try
    {
        DbConnection1.Open();
        OdbcCommand DbCommand1 = DbConnection1.CreateCommand();
        //DbCommand1.CommandText = "UPDATE TBL_ITHELPDESK SET STATUS='"+ chkClosed.Text +"',CLOSED_BY='"+drpClosedBy.Text+"',CLOSED_ON=TO_DATE('"+txtClosedOn.Text.ToString().Trim()+"','MM-DD-YYYY')WHERE CALL_NO='" + txtCallNo.Text + "'";
        DbCommand1.CommandText = "insert into tblhelp(grid) values('" + TextBox7.Text.Replace("'", "''").Trim() + "')";
    TextBox7.Text=DbCommand1.CommandText.ToString();
        int t1 = DbCommand1.ExecuteNonQuery();
        if (t1 == 1)
        {
            DbConnection1.Close();
        }
        else
        {
        }
    }
    catch (Exception ex)
    {
    }
}

String Literal对于Clob类型来说太长了

字符串字面值限制为4000字节。如果您试图将数据插入CLOB,您的代码将需要使用绑定变量并绑定LOB数据(出于与安全性和性能相关的许多其他原因,您应该这样做)。您得到的错误强烈暗示您正在做类似在字符串中构建SQL语句的事情,该字符串包含您想要插入的文字数据。

使用命令参数:

try
{
    DbConnection1.Open();
    OdbcCommand DbCommand1 = DbConnection1.CreateCommand();
    DbCommand1.CommandText = "INSERT INTO tblhelp (grid) VALUES (?)";
    OdbcParameter param1 = new OdbcParameter("param1", OdbcType.VarChar);
    param1.Value = TextBox7.Text;
    DbCommand1.Parameters.Add(param1);
    Int32 t1 = DbCommand1.ExecuteNonQuery();
    if (t1 == 1)
    {
        DbConnection1.Close();
    }
    else
    {
    }
}
catch (Exception ex)
{
    //do something!
}