0
當我嘗試輸入值,然後單擊提交按鈕,它說,在異常的錯誤錯誤插入數據到多個表與相關刪除級聯
您的SQL語法錯誤;檢查對應於你的MySQL服務器版本正確的語法在1號線
int MobileNo;
string Mobile = txtMobile.Text;
int.TryParse(Mobile, out MobileNo);
MySqlConnection connection = new MySqlConnection(MyConnectionString);
MySqlCommand cmd;
connection.Open();
try
{
cmd = connection.CreateCommand();
cmd.CommandText = "INSERT INTO phonebook(Id,Name,MobileNo)VALUES(@Id,@Name,@MobileNo)";
cmd.Parameters.AddWithValue("@Id", int.Parse(txtId.Text));
cmd.Parameters.AddWithValue("@Name", txtName.Text);
cmd.Parameters.AddWithValue("@MobileNo", Mobile);
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
cmd.CommandText = "INSERT INTO email(Id,email)VALUES(,@email)";
cmd.Parameters.AddWithValue("@Id", int.Parse(txtId.Text));
cmd.Parameters.AddWithValue("@email", txtEmail1.Text);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (connection.State == ConnectionState.Open)
{
connection.Close();
LoadData();
}
}
您在第二個查詢中沒有包含該Id ..請包括它然後檢查。 –