我试图将记录插入m sql数据库。我的第一个值是1然后是1001.我的插入将放置第一个值1,正确但1001超出它返回null。如何更改此值以读取值而不使用索引,因为它不按顺序排列?
插入方法:
SqlCommand addJob = new SqlCommand(@"INSERT INTO JobNumber ( JobID, CustomerID, JobDescription, IsActive) VALUES ( @JobID, (SELECT @CustomerID FROM Customer C WHERE C.CustomerID = @CustomerID), @JobDescription, @IsActive)", dbConn);
addJob.Parameters.AddWithValue("@JobID", Convert.ToInt32(jobidTextBox.Text));
addJob.Parameters.AddWithValue("@CustomerID", Convert.ToInt32(customeridComboBox.SelectedIndex) + 1);
addJob.Parameters.AddWithValue("@JobDescription", jobdescriptionTextBox.Text);
addJob.Parameters.AddWithValue("@IsActive", isactiveCheckBox.Checked);
dbConn.Open();
addJob.ExecuteNonQuery();
答案 0 :(得分:0)
尝试使用组合框的选定文本/所选项属性而不是索引。
答案 1 :(得分:0)
你应该像这样检索你的文字项目
addJob.Parameters.AddWithValue("@CustomerID", Convert.ToInt32(customeridComboBox.Items[customeridComboBox.SelectedIndex+ 1] );