简体   繁体   English

无法从C#将inkPicture插入SQL Server数据库

[英]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.

相关问题 SQL Server C#无法插入数据库 - SQL Server C# can't insert in to the database 使用C#,EF和SQL Server,仅将不存在的行从Excel文件插入数据库 - Insert into database from an Excel file only rows that don't exist, using C#, EF, and SQL Server 无法将值动态创建的文本框插入或更新到SQL Server数据库Windows Forms C#中 - Can't Insert or update values to dynamically created textbox into SQL Server database Windows Forms C# 将 C# 中的日期时间插入 SQL Server 数据库 - Insert datetime from C# into SQL Server database 从C#将特殊字符插入SQL Server 2008数据库 - insert special character into SQL Server 2008 database from c# 从C#将整数值插入SQL Server数据库 - Insert integer value into SQL Server database from C# 错误:无法使用C#将数据插入SQL Server - Error: can't insert data into SQL Server with C# INSERT语句不插入使用C#Winform的SQL Server数据库 - INSERT Statement Doesn't Insert into SQL Server Database working with C# Winform 使用C#动态将所有表的数据从一个SQL Server数据库插入第二个数据库 - Insert data from one SQL Server database into a second database for all tables dynamically using C# INSERT INTO,UPDATE命令不会将数据添加到C#中的SQL Server数据库中 - INSERT INTO, UPDATE commands don't add data to SQL Server database in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM