insert语句错误
protectedvoidButton1_Click(objectsender,EventArgse){stringusername=this.TextBox1.Text...
protected void Button1_Click(object sender, EventArgs e)
{
string username = this.TextBox1.Text;
int age = Convert.ToInt32(this.TextBox2.Text);
string sex = this.RadioButtonList1.Text;
string nation = this.TextBox3.Text;
string idf = this.TextBox4.Text;
string test_num = this.TextBox5.Text;
int m_test;
int.TryParse(this.TextBox6.Text,out m_test);
string types = this.DropDownList1.Text;
string tel = this.TextBox7.Text;
string qq = this.TextBox8.Text;
string addr = this.TextBox9.Text;
string f_school = this.TextBox10.Text;
string pos_num = this.TextBox11.Text;
string position = this.TextBox12.Text;
string profess = this.DropDownList2.Text;
string dic = this.TextBox13.Text;
string sql = string.Format("insert into student_stand(username,sex,age,nation,idf,test_num,m_test,types,tel,qq,addr,f_school,pos_num,position,profess,dic) values('{0}','{1}',{2},'{3}','{4}','{5}',{6},'{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}')", username, sex, age, nation, idf, test_num, m_test, types, tel, qq, addr, f_school, pos_num, position, profess, dic);
try
{
OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;Persist Security Info=True;data source=" + Server.MapPath("database2010/zyschool.mdb"));
conn.Open();
OleDbCommand cmd = new OleDbCommand(sql, conn);
if (cmd.ExecuteNonQuery() < 1)
{
Response.Write("<script language=javascript>");
Response.Write("alert('添加失败!');");
Response.Write("</script>");
Response.Write("<script language=javascript>javascript:history.go(-1)</script>");
}
else
{
Response.Write("<script language=javascript>");
Response.Write("alert('添加成功!');");
Response.Write("</script>");
Response.Write("<script language=javascript>javascript:location.href('school_stand.aspx')</script>");
}
}
catch(Exception ex)
{
Response.Write(sql);
//Response.End();
throw new Exception(ex.ToString());
}
报的错误是insert语句语法错误,错在哪了哦?? 展开
{
string username = this.TextBox1.Text;
int age = Convert.ToInt32(this.TextBox2.Text);
string sex = this.RadioButtonList1.Text;
string nation = this.TextBox3.Text;
string idf = this.TextBox4.Text;
string test_num = this.TextBox5.Text;
int m_test;
int.TryParse(this.TextBox6.Text,out m_test);
string types = this.DropDownList1.Text;
string tel = this.TextBox7.Text;
string qq = this.TextBox8.Text;
string addr = this.TextBox9.Text;
string f_school = this.TextBox10.Text;
string pos_num = this.TextBox11.Text;
string position = this.TextBox12.Text;
string profess = this.DropDownList2.Text;
string dic = this.TextBox13.Text;
string sql = string.Format("insert into student_stand(username,sex,age,nation,idf,test_num,m_test,types,tel,qq,addr,f_school,pos_num,position,profess,dic) values('{0}','{1}',{2},'{3}','{4}','{5}',{6},'{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}')", username, sex, age, nation, idf, test_num, m_test, types, tel, qq, addr, f_school, pos_num, position, profess, dic);
try
{
OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;Persist Security Info=True;data source=" + Server.MapPath("database2010/zyschool.mdb"));
conn.Open();
OleDbCommand cmd = new OleDbCommand(sql, conn);
if (cmd.ExecuteNonQuery() < 1)
{
Response.Write("<script language=javascript>");
Response.Write("alert('添加失败!');");
Response.Write("</script>");
Response.Write("<script language=javascript>javascript:history.go(-1)</script>");
}
else
{
Response.Write("<script language=javascript>");
Response.Write("alert('添加成功!');");
Response.Write("</script>");
Response.Write("<script language=javascript>javascript:location.href('school_stand.aspx')</script>");
}
}
catch(Exception ex)
{
Response.Write(sql);
//Response.End();
throw new Exception(ex.ToString());
}
报的错误是insert语句语法错误,错在哪了哦?? 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询