字符串文字对于Clob类型太长

字符串文字对于Clob类型太长

本文介绍了字符串文字对于Clob类型太长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含clob列的表.我想将HTML数据保存到那个(c#)中.保存时,出现错误:String Literal太长.我要存储的字符串长度是8048个字符

I have table containing clob column.I want to save HTML data into that(c#).When i save , i get an error: String Literal too long.the string length I'm storing is 8048 characters

有人可以帮助我吗?提前致谢表格是: 创建表tblhelp ( 网格长 )

Can any one help me?Thanks in advancetable is: CREATE TABLE tblhelp ( GRID LONG )

 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)
    {

    }
}

推荐答案

使用命令参数:

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!
}

这篇关于字符串文字对于Clob类型太长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 23:26