Ale*_*123 6 c# forms database-connection
我一直收到标题中提到的错误,但似乎无法通过。
这是我的代码:
strSig = sigPlusNET1.GetKeyReceiptAscii()
sigPlusNET1.LCDRefresh(1, 210, 3, 14, 14);
if (sigPlusNET1.NumberOfTabletPoints() > 0)
{
sigPlusNET1.LCDRefresh(0, 0, 0, 240, 64);
Font f = new System.Drawing.Font("Arial", 9.0F, System.Drawing.FontStyle.Regular);
sigPlusNET1.LCDWriteString(0, 2, 35, 25, f, "Semnatura a fost salvata.");
SqlConnection connection = new SqlConnection("Data Source=xxx;Initial Catalog=xxx;Persist Security Info=True;User ID=xxx;Password=xxx; MultipleActiveResultSets=True");
connection.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO cstmae_Signatures(Signature)values("+ strSig +")", connection);
cmd.ExecuteNonQuery();
connection.Close();
Run Code Online (Sandbox Code Playgroud)
这是一个标准的Forms应用程序。
我究竟做错了什么?我试过将strSig转换为Int32,什么都没有,类型现在是beeing发送的8位int,但是问题出在sql连接上。
小智 -1
我有同样的错误“无法将类型为“System.Data.SqlClient.SqlInternalConnectionTds”的对象转换为类型为“System.Data.SqlClient.SqlInternalConnectionSmi”。”
query = "UPDATE dbo.History SET Volume = @Volume WHERE Symbol = @Symbol AND [start] = @Date; ";
using (SqlConnection con = new SqlConnection(builder.ConnectionString))
using (SqlCommand cmd = new SqlCommand(query, con))
{
cmd.Parameters.Add("@Symbol", SqlDbType.NVarChar, 50).Value = ti.Symbol;
cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = ti.Date;
cmd.Parameters.Add("@Volume ", SqlDbType.Float).Value = ti?.Volume;
try
{
cmd.ExecuteNonQuery();
}
catch (System.InvalidCastException e)
{
throw;
}
con.Close();
}
Run Code Online (Sandbox Code Playgroud)
数据库中不会保存任何内容,获取消息的唯一方法是通过 cmd.ExecuteNonQuery() 方法的“非公共成员”。当我检查参数值时,所有参数值都已存在且正确。