asp.net网站开发,数据插入数据库(SQL)出错
我用vs2012学习网站开发,在.aspx文件中用了TextBox(id= TextBox1)和一个“提交”按钮(Button1),我想用“提交”把TextBox中的值插入到数据库表(dbo.data)中,但是出错插不进去。麻烦各位帮忙看看该怎么改,我是学生,刚接触asp.net不久,希望解答详细点儿,谢谢!
protected void Button1_Click(object sender, EventArgs e)
{
string constr = "Data Source=Administrator-PC;Initial Catalog=web_data;Integrated Security=True";
SqlConnection con = new SqlConnection(constr);
con.Open();
string text = TextBox1.Text.ToString();
string sqlstr = "insert into data values (Text, null, null);";
SqlCommand cmd = new SqlCommand(sqlstr, con);
cmd.ExecuteNonQuery();
con.Close();
}
点击“提交”后的错误信息:
------解决方案--------------------
好吧,没看仔细,9楼也是错的……
string sqlstr = "insert into [data]([姓名]) values ('" + text + "')";
------解决方案--------------------string sqlstr = "insert into data values ('"+text+"', null, null)";