看看,我的SQL语句错在哪里?
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 语句的语法错误.
谢谢大家!
[解决办法]
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)这个地方,好象都是问号吧?
[解决办法]
去查询分析器调试下
[解决办法]
检查下数据类型是不是一样,还有字符串是不是太长了。
语法上没错,可能是数据的问题
[解决办法]
设断点,一个个字段跟踪一下看看,这两天搞ASP,不能跟踪,郁闷坏了。
[解决办法]
把各个参数对应的值都取出来,在access的sql试图下执行看看。
[解决办法]
跟踪一下,把sql语句抓出来看看!
[解决办法]
设断点吧!! 很难看出错误的!
[解决办法]
这个问题我也遇到过,当时我的问题就出现在数据类型还有长度上面,你最好检查一下,你输入的长度是不是太长了
[解决办法]
因为字段里面有关键字,你全部用中括号扩起来
比如 [name],[sex]
[解决办法]
好吓人阿,那么多参数