Visual Studio针对TextBox对象

时间:2017-03-04 14:59:21

标签: c# sql winforms

错误:

  

从对象类型System.Windows.Forms.TextBox到已知的托管提供者本机类型

不存在任何映射

我不知道为什么我的Visual Studio会给我这种类型的错误,任何sugestions?

代码段:

            MemoryStream ms = new MemoryStream();
            Bitmap bmpImage = new Bitmap(pictureBox1.Image);
            bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] data = ms.GetBuffer();
            cc.con = new SqlConnection(cs.DBConn);
            cc.con.Open();
            string cb = "insert into Product(P_ID,ProductID,ProductName,SubCategoryID,Features,Price,VAT,ST,Discount,Photo) VALUES (@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10)";
            cc.cmd = new SqlCommand(cb);
            cc.cmd.Connection = cc.con;
            cc.cmd.Parameters.AddWithValue("@d1", txtID.Text);
            cc.cmd.Parameters.AddWithValue("@d2", txtProductID);
            cc.cmd.Parameters.AddWithValue("@d3", txtProductName.Text);
            cc.cmd.Parameters.AddWithValue("@d4", txtSubCategoryID.Text);
            cc.cmd.Parameters.AddWithValue("@d5", txtFeatures.Text);
            cc.cmd.Parameters.AddWithValue("@d6", txtPrice.Text);
            cc.cmd.Parameters.AddWithValue("@d7", txtVAT.Text);
            cc.cmd.Parameters.AddWithValue("@d8", txtServiceTax.Text);
            cc.cmd.Parameters.AddWithValue("@d9", txtDiscount.Text);
            cc.cmd.Parameters.AddWithValue("@d10",data);
            cc.cmd.ExecuteReader();
            cc.con.Close();
            st1 = lblUser.Text;
            st2 = "adicionou um produto '" + txtProductName.Text + "'";
            cf.LogFunc(st1,System.DateTime.Now,st2);

1 个答案:

答案 0 :(得分:1)

cc.cmd.Parameters.AddWithValue("@d2", txtProductID);更改为cc.cmd.Parameters.AddWithValue("@d2", txtProductID.Text);