【发布时间】:2013-07-08 11:31:15
【问题描述】:
我正在插入记录,我的对象之一是组合框。组合框连接到表。当我插入此错误时出现:
将参数值从 DataRowView 转换为 Int32 失败
我的代码:
cn.Open();
SqlCommand Insert = new SqlCommand();
Insert.Connection = cn;
Insert.CommandType = CommandType.Text;
Insert.CommandText = "INSERT INTO Ticket VALUES (CustomerID, Date, Store, Amount, NoStub) ";
Insert.Parameters.Add("CustomerID", SqlDbType.Int).Value = cboName.SelectedValue;
Insert.Parameters.Add("Date", SqlDbType.DateTime).Value = dtpDate.Value.Date.ToString();
Insert.Parameters.Add("Store", SqlDbType.NVarChar).Value = txtStore.Text;
Insert.Parameters.Add("Amount", SqlDbType.Decimal).Value = txtAmount.Text;
Insert.Parameters.Add("NoStub", SqlDbType.Decimal).Value = txtStub.Text;
Insert.ExecuteNonQuery();
cn.Close();
【问题讨论】:
-
添加一些你已经尝试过的代码,这样你就可以期待更快的答案,而不是听起来太笼统
-
你能解决这个问题吗?如果您解决了它,并且其中一个答案是帮助您解决问题的答案,那么最好接受它作为答案。如果您仍然遇到问题,这将有助于您告诉您卡在哪里。
标签: c# sql-server sql-server-2008 tsql ado.net