DBHelper D = new DBHelper();
MySqlConnection M = D.getconn();
M.Open();
MySqlCommand cmd = new MySqlCommand("insert into test1(name,department,specification,amount,packing,declarationInspectionDate,assayDate,reportDate,commodityBatchNumber,inspectionbasis,conclusion,assessor,analyst,laboratoryTechnician) values(@name,@department,@specification,@amount,@packing,@declarationInspectionDate,@assayDate,@reportDate,@commodityBatchNumber,@inspectionbasis,@conclusion,@assessor,@analyst,@laboratoryTechnician)",M);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@name", this.textBox1.Text.Trim());
cmd.Parameters.AddWithValue("@department", this.textBox2.Text.Trim());
cmd.Parameters.AddWithValue("@specification", this.textBox3.Text.Trim());
cmd.Parameters.AddWithValue("@amount", float.Parse(this.textBox4.Text.Trim().ToString()));
cmd.Parameters.AddWithValue("@packing", this.textBox5.Text.Trim());
cmd.Parameters.AddWithValue("@declarationInspectionDate", this.dateTimePicker1.Text.Trim());
cmd.Parameters.AddWithValue("@assayDate", this.dateTimePicker2.Text.Trim());
cmd.Parameters.AddWithValue("@reportDate", this.dateTimePicker3.Text.Trim());
cmd.Parameters.AddWithValue("@commodityBatchNumber", this.textBox8.Text.Trim());
cmd.Parameters.AddWithValue("@inspectionbasis", this.textBox10.Text.Trim());
cmd.Parameters.AddWithValue("@conclusion", this.textBox11.Text.Trim());
cmd.Parameters.AddWithValue("@assessor", this.textBox14.Text.Trim());
cmd.Parameters.AddWithValue("@analyst", this.textBox13.Text.Trim());
cmd.Parameters.AddWithValue("@laboratoryTechnician", this.textBox12.Text.Trim());
int j = cmd.ExecuteNonQuery();
用以上代码,我为什么不能实现对数据库的操作?显示插入成功,但是数据库中相应字段全都是空的,也就是说,cmd.Parameters.AddWithValue("@laboratoryTechnician", this.textBox12.Text.Trim());中没有给相应的参数赋值,一个也没有,很难受,我不知道怎么改才行。