[英]Can't insert inkPicture into SQL Server database from C#
Actually, I am working on a Windows application and I want to add inkPicture
to capture users signatures to the database. 实际上,我在Windows应用程序上工作,我想添加
inkPicture
来捕获用户签名到数据库。 The signature column data type is varbinary
. 签名列的数据类型为
varbinary
。 The problem is that the record is added to the database but it shows it as null only. 问题是该记录已添加到数据库,但仅将其显示为null。
This is what I have done so far: 到目前为止,这是我所做的:
string con = "Data Source=SAIUNIFLOW;Initial Catalog=documentfollowup;Integrated Security=True";
byte[] saveInk = (byte[])axInkPicture1.Ink.Save(InkPersistenceFormat.IPF_GIF, InkPersistenceCompressionMode.IPCM_Default);
cmdDatabase = new SqlCommand();
cmdDatabase.Connection = conDatabase;
// cmdDatabase.CommandText = "insert into manage (Signature) values(Singature); ";
cmdDatabase.CommandText= "insert into manage (Signature)" + "values('" + axInkPicture1 + "'); ";
cmdDatabase.Parameters.AddWithValue("@Signature", saveInk);
I'm using tablet for getting the signatures but when I click the insert button, I receive that error: 我使用平板电脑获取签名,但是当我单击插入按钮时,收到该错误:
Cannot insert the null value into column Signature, table doesn't allow nulls.
无法将空值插入“签名”列,表不允许空值。
Hopefully to help me to solve this error. 希望能帮助我解决此错误。
The problem is that you don't set the value of @Signature
parameter. 问题是您没有设置
@Signature
参数的值。 And also try setting the SqlDbType
property of the parameter. 并尝试设置参数的
SqlDbType
属性。
Use this instead: 使用此代替:
cmdDatabase.CommandText= "insert into manage (Signature) values(@Signature);";
var signatureParam = cmdDatabase.Parameters.AddWithValue("@Signature", saveInk);
signatureParam.SqlDbType = SqlDbType.VarBinary;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.