用c#如何操作BLOB字段..
我后台是通过Firebird连接的Interbase数据库,现在Insert、Update、delete都没问题,但唯一的就是不能写入BLOB字段值,或者更新BLOB字段值..
网上大部分的办法是流方式,或者二进制转换,但都是以文件或者图片为例...
我现在想把Textbox.Text的内容存入 BLOB字段里面,找了好多天资料一直没有好的办法,希望各位达人给解决一下..
现在数据连接都没问题,只是不知道该如何插入BLOB的值,或者说,如何Update这个BLOB字段的值...
[解决办法]
对于有二进制数组的字段,不要采用直接字符串拼接的方式,而要采用SqlParameter 参数传入:
OdbcConnection cn = new OdbcConnection("DSN=Testgdb;UID=SYSDBA;PWD=masterkey;"); try { //写入BLOB字段 byte[] myBlob = System.Text.Encoding.UTF8.GetBytes(TextBoxDetails.Text); string myString = string.Format("update customer set SUMMARY= (@summary) where CUSTID='{0}' and SNAME='{1}'",TextBoxNo.Text , TextBoxCorp.Text); cn.Open(); OdbcCommand cmd = new OdbcCommand(myString, cn); cmd.Parameters.Add("@summary", SqlDbType.Image).Value = myData; Response.Write(myString); cmd.ExecuteNonQuery(); } catch (OdbcException ex) { Response.Write(ex.Message); } finally { cn.Close(); }