无法将类型为'System.Data.SqlClient.SqlInternalConnectionTds'的对象转换为类型'System.Data.SqlClient.SqlInternalConnectionSmi'

7
我将不断收到标题中提到的错误,似乎无法解决。
以下是我的代码:
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();

这是一个标准的表单应用程序。

我做错了什么?我尝试将strSig转换为Int32,但没有任何效果,现在类型是一个8位整数被发送,但问题似乎与SQL连接有关。

1个回答

0

我遇到了同样的错误:“无法将类型为'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();
}

没有将任何内容保存到数据库中,获取消息的唯一方式是通过cmd.ExecuteNonQuery()方法的“非公共成员”。当我检查参数值时,它们都存在且正确。


1
那怎么回答问题呢? - A_Arnold

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接