本文介绍了我无法在表格中插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
protected void Submit_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS; database= Registration; trusted_connection=yes");
conn.Open();
SqlCommand com = new SqlCommand("insert into register(Username, password, email id, first name) values(" + TextBoxUS.Text + "," + TextBoxPass.Text + "," + TextBoxEA.Text + "," + TextBoxFN.Text + ") ", conn);
com.ExecuteNonQuery();
}
很抱歉,发帖之前
该错误显示为未处理SqlException"
错误在此行= com.ExecuteNonQuery();
I am sorry for before post
The error its showing as "SqlException was unhandled "
The error is in this line= com.ExecuteNonQuery(); it showing "Incorrect syntax near ''id''."
推荐答案
...
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS; database= Registration; trusted_connection=yes");
conn.Open();
SqlCommand com = new SqlCommand("insert into register(Username, password, [email id], [first name]) values(@username, @password, @emailid, @firstname) ", conn);
com.Parameters.AddWithValue("@username", TextBoxUS.Text);
com.Parameters.AddWithValue("@password", TextBoxPass.Text);
com.Parameters.AddWithValue("@emailid", TextBoxEA.Text);
com.Parameters.AddWithValue("@firstname", TextBoxFN.Text);
com.ExecuteNonQuery();
...
这篇关于我无法在表格中插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!