这是您可以遵循的示例 我已经粘贴了我刚刚写的内容的副本 您可能希望遵循此内容以供将来参考 注意如何使用该Parameters.AddWithValue()
方法而不是使用Quoted
值构建字符串查询字符串
private void btnInsert_Click(object sender, EventArgs e)
{
using(SqlConnection con = new SqlConnection(connString))
{
con.Open();
string Sql = "INSERT INTO Uyeleri (dID, FullName, Address, Mobile, Email, Comments ) " +
"VALUES (@id, @name, @address, @mobile, @email, @comments");
using(SqlCommand cmd = new SqlCommand(Sql, con))
{
cmd.Parameters.AddWithValue("@id", txtdID.Text);
cmd.Parameters.AddWithValue("@name", txtAdiSoyadi.Text);
cmd.Parameters.AddWithValue("@address", txtAddress.Text);
cmd.Parameters.AddWithValue("@mobile", txtMobile.Text);
cmd.Parameters.AddWithValue("@email", txtEmail.Text);
cmd.Parameters.AddWithValue("@comments", txtComments.Text);
cmd.ExecuteNonQuery();
}
}