丧事送花圈的来历:请高手指教.NET中INSERT语句问题,在线等,谢谢!!!!!

来源:百度文库 编辑:高校问答 时间:2024/04/28 01:32:06
string strsql;
strsql="insert into userinfo(wendu,shidu,jianceshijian,chixushijian,bianhuadu)values("; strsql+=",'"+TextBox1.Text.ToString()+"'";
strsql+=",'"+TextBox2.Text.ToString()+"'";
strsql+=",'"+TextBox3.Text.ToString()+"')";
strsql+=",'"+TextBox4.Text.ToString()+"')";
strsql+=",'"+TextBox5.Text.ToString()+"')";
SqlCommand com = new SqlCommand(strsql,con);
SqlDataReader rd=com.ExecuteReader();
this.DataGrid1.DataBind();
为什么报错说
"SqlCommand com = new SqlCommand(strsql,con);"
逗号附近有语法错误?是什么错误?

试试这样写:

strsql="insert into userinfo(wendu,shidu,jianceshijian,chixushijian,bianhuadu) values(";
strsql+=",'"+TextBox1.Text.ToString()+"'";
strsql+=",'"+TextBox2.Text.ToString()+"'";
strsql+=",'"+TextBox3.Text.ToString()+"'";
strsql+=",'"+TextBox4.Text.ToString()+"'";
strsql+=",'"+TextBox5.Text.ToString()+"')";

strsql+=",'"+TextBox3.Text.ToString()+"')";
strsql+=",'"+TextBox4.Text.ToString()+"')";
有错误!

SQL标准语句为
insert into tableName ([column1],[column2]) values('"+ textBox1.text.ToString() +"','"+ textBox2.text.ToString() +"');

楼上的说法是正确的
更改为

strsql="insert into userinfo(wendu,shidu,jianceshijian,chixushijian,bianhuadu) values(";
strsql+=",'"+TextBox1.Text.ToString()+"'";
strsql+=",'"+TextBox2.Text.ToString()+"'";
strsql+=",'"+TextBox3.Text.ToString()+"'";
strsql+=",'"+TextBox4.Text.ToString()+"'";
strsql+=",'"+TextBox5.Text.ToString()+"')";