简体   繁体   中英

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. The signature column data type is varbinary . The problem is that the record is added to the database but it shows it as null only.

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. And also try setting the SqlDbType property of the parameter.

Use this instead:

cmdDatabase.CommandText= "insert into manage (Signature) values(@Signature);";
var signatureParam = cmdDatabase.Parameters.AddWithValue("@Signature", saveInk);
signatureParam.SqlDbType = SqlDbType.VarBinary;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM