2 回答
TA贡献2036条经验 获得超8个赞
因为你还没有执行你的命令:
.... cmd.Parameters.AddWithValue("@lname", textBox2.Text); cmd.ExecuteNonQuery();
语句的固定版本insert
应该是这样的:
"INSERT INTO tesTable (fname,lname) VALUES (@fname,@lname)"
还需要补充一点,直接指定类型并使用属性Value
比AddWithValue
:
cmd.Parameters.Add("@lname", SqlDbType.VarChar).Value = textBox2.Text;
TA贡献1859条经验 获得超6个赞
private void btnaddsave_Click(object sender, EventArgs e)
{
try
{
string connection1 = "server=localhost;user id=root;password=1234;database=library_system";
con = new MySqlConnection(connection1);
con.Open();
string q = "Insert Into library_system.add_book(Book_No,Book_Name)values('"+tbbno.Text+"','" + tbbn.Text+ "')";
cm1 = new MySqlCommand(q, con);
cm1.ExecuteNonQuery();
//con.Open();
MessageBox.Show("data saved", "information", MessageBoxButtons.OK, MessageBoxIcon.Information);
con.Close();
// load();
tbbno.Text = "";
tbbn.Text = "";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
- 2 回答
- 0 关注
- 156 浏览
添加回答
举报