使用insert intio语句出现语法错误,请指点,谢谢
在插入数据的时候提示insert into 语法错误,帮我看看错在哪里,我使用的是Access数据库,谢谢
protected void btn_submit_Click(object sender, EventArgs e)
{
string CnnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + Server.MapPath( "lmyfback.mdb ");
OleDbConnection con = new OleDbConnection(CnnString);
con.Open();
string sex = "0 ";
string jiameng = "0 ";
string net = "0 ";
string paper = "0 ";
string friend = "0 ";
string qita1 = "0 ";
string shop = "0 ";
string select = "0 ";
string market = "0 ";
string tese = "0 ";
string pin = "0 ";
string tixi = "0 ";
string qita2 = "0 ";
string fx = "0 ";
string fy = "0 ";
string tj = "0 ";
string noneTS = "0 ";
string qj = "0 ";
string yx = "0 ";
string qita3 = "0 ";
if(this.rbtn_man.Checked)
{
sex = "男 ";
}
if(this.rbtn_woman.Checked)
{
sex = "女 ";
}
if(this.ckb_jm.Checked)
{
jiameng = "1 ";
}
if(this.ckb_net.Checked)
{
net = "1 ";
}
if(this.ckb_paper.Checked)
{
paper = "1 ";
}
if (this.ckb_friend.Checked)
{
friend = "1 ";
}
if (this.ckb_qita1.Checked)
{
qita1 = "1 ";
}
if(this.rbtn_yes.Checked)
{
shop = "1 ";
}
if(this.rbtn_none.Checked)
{
shop = "0 ";
}
if(this.rbtn_shi.Checked)
{
select = "1 ";
}
if(this.rbtn_fou.Checked)
{
select = "2 ";
}
if(this.rbtn_kl.Checked)
{
select = "3 ";
}
if(this.ckb_market.Checked)
{
market = "1 ";
}
if(this.ckb_tese.Checked)
{
tese = "1 ";
}
if(this.ckb_pin.Checked)
{
pin = "1 ";
}
if(this.ckb_tixi.Checked)
{
tixi = "1 ";
}
if(this.ckb_qita2.Checked)
{
qita2 = "1 ";
}
if(this.ckb_fx.Checked)
{
fx = "1 ";
}
if(this.ckb_fy.Checked)
{
fy = "1 ";
}
if(this.ckb_tj.Checked)
{
tj = "1 ";
}
if(this.ckb_noneTS.Checked)
{
noneTS = "1 ";
}
if(this.ckb_qj.Checked)
{
qj = "1 ";
}
if(this.ckb_yx.Checked)
{
yx = "1 ";
}
if(this.ckb_qita3.Checked)
{
qita3 = "1 ";
}
OleDbCommand cmd = new OleDbCommand( "insert into lmyfback([name],[sex],[job],[jiguan],[tel],[email],[jiameng],[net],[paper],[friend],[qita1],[invest],[area],[shop],[mj],[impress],[select],[market],[tese],[pin],[tixi],[qita2],[fx],[fy],[tj],[noneTS],[qj],[yx],[qita3],[yj]) values( ' " + this.tbx_name.Text.Trim() + " ', ' " + sex + " ', ' " + this.tbx_job.Text.Trim() + " ', ' " + this.tbx_jiguan.Text.Trim() + " ', ' " + this.tbx_tel.Text.Trim() + " ', ' " + this.tbx_email.Text.Trim() + " ', ' " + jiameng + " ', ' " + net + " ', ' " + paper + " ', ' " + friend + " ', ' " + qita1 + " ', ' " + this.tbx_invest.Text.Trim() + " ', ' " + this.tbx_area.Text.Trim() + " ', ' " + shop + " ', ' " + this.tbx_mj.Text.Trim() + " ', ' " + this.tbx_impress.Text.Trim() + " ', ' " + select + " ', ' " + market + " ', ' " + tese + " ', ' " + pin + " ', ' " + tixi + " ', ' " + qita2 + " ', ' " + fx + " ', ' " + fy + " ', ' " + tj + " ', ' " + noneTS + " ', ' " + qj + " ', ' " + yx + " ', ' " + qita3 + " ', ' " + this.tbx_yj.Text.Trim() + " ' ", con);
try
{
cmd.ExecuteNonQuery();
Response.Write( " <script> window.alert( '加盟申请提交成功,谢谢您的支持! '); </script> ");
}
catch (Exception ex)
{
Response.Write(ex.Message);
//Response.Write( " <script> window.alert( '加盟申请提交失败,请稍后再试... '); </script> ");
}
finally
{
con.Close();
}
}
[解决办法]
[name]
把中括号去了试一下
[解决办法]
一次拼这么长的 sql , 看花了 .....
[解决办法]
这样
string strSQL = "insert into lmyfback([name],[sex],[job],[jiguan],[tel],[email],[jiameng],[net],[paper],[friend],[qita1],[invest],[area],[shop],[mj],[impress],[select],[market],[tese],[pin],[tixi],[qita2],[fx],[fy],[tj],[noneTS],[qj],[yx],[qita3],[yj]) values( ' " + this.tbx_name.Text.Trim() + " ', ' " + sex + " ', ' " + this.tbx_job.Text.Trim() + " ', ' " + this.tbx_jiguan.Text.Trim() + " ', ' " + this.tbx_tel.Text.Trim() + " ', ' " + this.tbx_email.Text.Trim() + " ', ' " + jiameng + " ', ' " + net + " ', ' " + paper + " ', ' " + friend + " ', ' " + qita1 + " ', ' " + this.tbx_invest.Text.Trim() + " ', ' " + this.tbx_area.Text.Trim() + " ', ' " + shop + " ', ' " + this.tbx_mj.Text.Trim() + " ', ' " + this.tbx_impress.Text.Trim() + " ', ' " + select + " ', ' " + market + " ', ' " + tese + " ', ' " + pin + " ', ' " + tixi + " ', ' " + qita2 + " ', ' " + fx + " ', ' " + fy + " ', ' " + tj + " ', ' " + noneTS + " ', ' " + qj + " ', ' " + yx + " ', ' " + qita3 + " ', ' " + this.tbx_yj.Text.Trim() + " ' "
OleDbCommand cmd = new OleDbCommand()
cmd.CommandText = strSql;
然后在string strSql 这句话前边设个断点,看看它具体的值是什么
[解决办法]
语法错误?
先Response.Write(strSQL )看是啥,去分析器执行
[解决办法]
自己输出好好检查
Response.Write(cmd.CommandText);
[解决办法]
自己输出好好检查
设置断点,或者输出sql语句,粘贴到查询分析器里看看能否执行,具体分析是哪里的错误
[解决办法]
太长的 sql ,频繁的拼接,建议使用 StringBuilder,并用 Format, 类似如下用法
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.Append( "insert into lmyfback([name],[sex],[job], ...) values ");
sqlBuilder.AppendFormat( "( '{0} ', '{1} ', '{2} ', ...) ", this.tbx_name.Text.Trim(), sex , this.tbx_job.Text.Trim(), ....);
cmd.CommmandText = sqlBuilder.ToString();
[解决办法]
自己调试一下吧,把你拼接的SQL拿出来看一下有没有问题
[解决办法]
眼花........
自己单步调试,把strSQL 的值弄出来在SQL里试下就知道了
[解决办法]
也建议设置一个断点到查询分析器中看看insert到底有什么错误!
[解决办法]
把sql语句搞出来,这样谁看了都眼花。
[解决办法]
输出SQL去查询分析器看看呀
[解决办法]
怎么性欲值还有140的啊````这么高啊````
哈哈``玩笑``
------解决方案--------------------
其实不用看 估计是你 对应的字符串类型的地方 你少给了 单引号。。。
[解决办法]
语法错误?
先Response.Write(strSQL )看是啥,去分析器执行
去查询分析器 一运行就知道
[解决办法]
其实不用看 估计是你 对应的字符串类型的地方 你少给了 单引号。。。
或者是你数据库中字段为int型的多加了单引号
[解决办法]
眼花了,先response.write(string),string 为你的sql语句,看看出什么错误,再改正,或者单步调调。。
[解决办法]
编程习惯很差,这么花,很多人都没耐心看。貌似字段名称不需要中括号的