您的SQL语法有错误; 检查与MySQL服务器版本对应的手册,以便在第1行的'where LastName = Iguin'附近使用正确的语法
我无法修复错误:(有人可以帮助我
这是我的代码
try { string contactNumVal = txtColContact.Text; if (contactNumVal.Length < 11) { MessageBox.Show("The Contact Number must have 11 digit"); } else { DialogResult dw; dw = MessageBox.Show("Are you sure you want to Edit this data", "Confirm Deletion", MessageBoxButtons.YesNo); if (dw == DialogResult.Yes) { string MyConString = "SERVER=localhost;" + "DATABASE=prototype_db;" + "UID=root;"; using (MySqlConnection connection = new MySqlConnection(MyConString)) { connection.Open(); DataTable dt = new DataTable(); using (MySqlDataAdapter da = new MySqlDataAdapter("Select Collector_ID, LastName, " + "FirstName,MiddleName,Address,ContactNo,BirtDay,Gender" + "from collector_profile where LastName like @clname", connection)) { da.SelectCommand.Parameters.AddWithValue("@clname", "%" + txtColLname.Text + "%"); da.Fill(dt); dt.Rows[0].BeginEdit(); dt.Rows[0][1] = txtColLname.Text; dt.Rows[0][2] = txtColFname.Text; dt.Rows[0][3] = txtColMname.Text; dt.Rows[0][4] = txtColAddress.Text; dt.Rows[0][5] = txtColContact.Text; dt.Rows[0][6] = dtpCbday.ToString(); dt.Rows[0][7] = cmbCgender.SelectedItem.ToString(); dt.Rows[0].EndEdit(); MySqlCommandBuilder cb = new MySqlCommandBuilder(da); da.Update(dt); connection.Close(); } } MessageBox.Show("Data is now updated"); } } } catch (Exception error) { MessageBox.Show(error.ToString()); }
Habib.. 5
您需要在SQL字符串之间Gender
和之间from
留出空格.
using (MySqlDataAdapter da = new MySqlDataAdapter("Select Collector_ID, LastName, " + "FirstName,MiddleName,Address,ContactNo,BirtDay,Gender " + //here "from collector_profile where LastName like @clname", connection))
对于将来的调试,请尝试从debug中复制SQL命令文本,然后在SQL Server中执行相同的操作以查看它是否有效.(这会让你更好地了解错误)