![](/img/trans.png)
[英]Unable to cast object of type 'System.Data.ProviderBase.DbConnectionClosedConnecting' to type 'System.Data.SqlClient.SqlInternalConnectionTds
[英]Unable to cast object of type 'System.Data.SqlClient.SqlInternalConnectionTds' to type 'System.Data.SqlClient.SqlInternalConnectionSmi'
我一直收到标题中提到的错误,我似乎无法通过这个。
这是我的代码:
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();
这是一个标准的Forms应用程序。
我究竟做错了什么? 我已经尝试将strSig转换为Int32而没有任何东西,现在的类型是一个8位的int正在发送,但问题是与sql连接的问题。
我有相同的错误“无法将类型'System.SData.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();
}
没有任何内容保存到数据库中,获取消息的唯一方法是通过cmd.ExecuteNonQuery()方法的“非公共成员”。 当我检查参数值时,那里有所有并且正确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.