private void button4_Click(object sender, EventArgs e) { MySqlConnection connection = new MySqlConnection("datasource=localhost;port=3306;Initial Catalog='liblib';Data Source=localhost;username=root;password=admin"); String query = "UPDATE loans SET dataRet=@data1 WHERE loans.idloans = @idloan"; MySqlCommand cmd = new MySqlCommand(query, connection); int id = Int32.Parse(textBox9.Text); cmd.Parameters.Add("@data1", MySqlDbType.Date).Value = dateTimePicker1.Value; cmd.Parameters.Add("@idloan", MySqlDbType.Int32).Value = id; connection.Open(); if (cmd.ExecuteNonQuery() == 1) { MessageBox.Show("Succesful!"); connection.Close(); FIllCard(); } else { MessageBox.Show("Error"); connection.Close(); }当我在phpmyadmin中执行此UPDATE查询时,它会工作并更新条目:更新贷款SET dataRet ='2017-5-6'WHERE loan.idloans = 23。但是问题是当我在Form whith参数中尝试它时。它总是返回“错误”消息(ExecuteNonQuery与1不同),并且当我检查数据库时没有更新。我数据库中变量的类型是:idloans-int; dataRet =日期;
- 1 回答
- 0 关注
- 108 浏览
添加回答
举报
0/150
提交
取消