protected void btn_submit_Click(object sender, EventArgs e)
{
string CnnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("feedback.mdb");
OleDbConnection con = new OleDbConnection(CnnString);
con.Open();
try
{
OleDbCommand cmd = new OleDbCommand("insert into feedback(name,sex,identity,address,xueli,jobUnit,duty,tel,mobile,marriage,child,food,city,info,dish,resume,invest,shopArea,intent,market,populace,industry,cooperate,mode,likeMode,proposer,time) values(@name,@sex,@identity,@address,@xueli,@jobUnit,@duty,@tel,@mobile,@marriage,@child,@food,@city,@info,@dish,@resume,@invest,@shopArea,@intent,@market,@populace,@industry,@cooperate,@mode,@likeMode,@proposer,@time)", con);
OleDbParameter para = new OleDbParameter("@name", OleDbType.VarChar, 50);
para.Value = this.tbx_name.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@sex", OleDbType.VarChar, 10);
para.Value = this.tbx_sex.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@identity", OleDbType.VarChar, 50);
para.Value = this.tbx_identity.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@address", OleDbType.VarChar, 50);
para.Value = this.tbx_address.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@xueli", OleDbType.VarChar, 30);
para.Value = this.tbx_xueli.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@zip", OleDbType.VarChar, 50);
para.Value = this.tbx_zip.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@jobUnit", OleDbType.VarChar, 50);
para.Value = this.tbx_jobUnit.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@duty", OleDbType.VarChar, 30);
para.Value = this.tbx_duty.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@tel", OleDbType.VarChar, 50);
para.Value = this.tbx_tel.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@mobile", OleDbType.VarChar, 50);
para.Value = this.tbx_mobile.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@marriage", OleDbType.VarChar, 20);
para.Value = this.tbx_marriage.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@child", OleDbType.VarChar, 10);
para.Value = this.tbx_child.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@food", OleDbType.VarChar, 10);
para.Value = this.tbx_food.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@city", OleDbType.VarChar, 50);
para.Value = this.tbx_city.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@info", OleDbType.VarChar, 50);
para.Value = this.tbx_info.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@dish", OleDbType.VarChar, 50);
para.Value = this.tbx_dish.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@resume", OleDbType.LongVarChar);
para.Value = this.tbx_dish.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@invest", OleDbType.VarChar, 50);
para.Value = this.tbx_invest.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@shopArea", OleDbType.VarChar, 50);
para.Value = this.tbx_shopArea.Text.Trim();
cmd.Parameters.Add(para);
if (this.rbtn_intent1.Checked)
{
para = new OleDbParameter("@intent", OleDbType.Integer);
para.Value = 1;
cmd.Parameters.Add(para);
}
else if (this.rbtn_intent2.Checked)
{
para = new OleDbParameter("@intent", OleDbType.Integer);
para.Value = 2;
cmd.Parameters.Add(para);
}
else if (this.rbtn_intent3.Checked)
{
para = new OleDbParameter("@intent", OleDbType.Integer);
para.Value = 3;
cmd.Parameters.Add(para);
}
else
{
para = new OleDbParameter("@intent", OleDbType.Integer);
para.Value = 4;
cmd.Parameters.Add(para);
}
para = new OleDbParameter("@market", OleDbType.VarChar, 50);
para.Value = this.tbx_market.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@populace", OleDbType.VarChar, 50);
para.Value = this.tbx_populace.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@industry", OleDbType.VarChar, 50);
para.Value = this.tbx_industry.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@cooperate", OleDbType.VarChar, 10);
para.Value = this.tbx_cooperate.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@people", OleDbType.VarChar, 50);
para.Value = this.tbx_people.Text.Trim();
cmd.Parameters.Add(para);
if (this.rbtn_mode1.Checked)
{
para = new OleDbParameter("@mode", OleDbType.Integer);
para.Value = 1;
cmd.Parameters.Add(para);
}
else if (this.rbtn_mode2.Checked)
{
para = new OleDbParameter("@mode", OleDbType.Integer);
para.Value = 2;
cmd.Parameters.Add(para);
}
else
{
para = new OleDbParameter("@mode", OleDbType.Integer);
para.Value = 3;
cmd.Parameters.Add(para);
}
para = new OleDbParameter("@likeMode", OleDbType.VarChar, 10);
para.Value = this.tbx_likeMode.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@proposer", OleDbType.VarChar, 50);
para.Value = this.tbx_proposer.Text.Trim();
cmd.Parameters.Add(para);
para = new OleDbParameter("@time", OleDbType.VarChar, 50);
para.Value = this.tbx_date.Text.Trim();
cmd.Parameters.Add(para);
cmd.ExecuteNonQuery();
Response.Write("<script>window.alert('提交数据成功!');</script>");
}
catch (Exception ex)
{
Response.Write(ex.Message);
//Response.Write("<script>window.alert('提交数据失败,请及时与管理员联系...');</script>");
}
finally
{
con.Close();
}
}
调试的时候提示:INSERT INTO 语句的语法错误.
谢谢大家!