C#一点小问题,求高手指点啊
程序代码:
private void Add_Click(object sender, EventArgs e) { if (cmbBarcode.Text == "") return; if (!chkCustomerID.Checked) nudDiscount.Value = 1; = string.Format("select ID,ISBN,Name,Price from Book where Barcode='{0}'",cmbBarcode.Text); SqlDataReader reader = null; try { reader = cmd.ExecuteReader(); if (reader.Read()) { object[] obj = new object[7]; obj[0] = reader["ID"]; obj[1] = reader["ISBN"]; obj[2] = reader["Name"]; obj[3] = reader["Price"]; obj[4] = nudNumber.Value; obj[5] = nudDiscount.Value; obj[6] = ((int)obj[3]) * ((int)obj[4]) * ((int)obj[5]); this.dataGridView1.Rows.Add(obj); } else { MessageBox.Show("没有符合条件的记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } catch (Exception exp) { MessageBox.Show("数据访问错误:" + exp.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (reader != null && !reader.IsClosed) reader.Close(); } }这段代码高手看了应该懂我的意思。。。
现在的问题就是运行之后数据库访问错误,指定转换无效!
求高手修改下代码 并告诉错误的原因。。。谢谢