本文介绍了插入查询错误在插入sql语句时显示语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了几次,但它显示错误。它无效。



保存代码如下。

I tried several times but it shows the error.it is not working.

Save Code as follows.

for (int i = 0; i < DGV_Fac_SMS.RowCount; i++)
{
      sql = "insert into Tb_Faculty_Schedule_Timetable [Name],[Mobile No],[Message];
      sql = sql + " values ( '" + (DGV_Fac_SMS.Rows[i].Cells[0].Value.ToString()) + "','" + (DGV_Fac_SMS.Rows[i].Cells[1].Value.ToString()) + "','" + (DGV_Fac_SMS.Rows[i].Cells[2].Value.ToString()) + "')";

      GFun.Error = " ";
      GFun.InsertAccessData(sql);
      if (GFun.Error.ToString() != "")
      {
             MessageBox.Show(GFun.Error.ToString(), "Error");
             return;
      }

      GFun.OleDbCon.Close();

      MessageBox.Show("Record Inserted Successfully", "Records Inserted", MessageBoxButtons.OK, MessageBoxIcon.Information);
}



当我点击保存按钮时,错误显示如下。


$ b插入到sql语句中的$ b


When I click the save button, error shows as follows.

syntax error in  insert into sql statement.





插入查询中的错误是什么?

我试了几次,但是显示错误。



What is the mistake in insert query ?
I tried several times, but it shows the error.

推荐答案

sql = "insert into Tb_Faculty_Schedule_Timetable [Name],[Mobile No],[Message];

sql = sql + " values ( '" + (DGV_Fac_SMS.Rows[i].Cells[0].Value.ToString()) + "','" + (DGV_Fac_SMS.Rows[i].Cells[1].Value.ToString()) + "','" + (DGV_Fac_SMS.Rows[i].Cells[2].Value.ToString()) + "')";





- >在第一行代码中,您最后错过了报价在分号之前,由 @Jegan Thiyagesan 说。



所以,它应该变成......



-> In first line of code, you missed a quote at last before semicolon as said by @Jegan Thiyagesan.

So, it should become...

sql = "insert into Tb_Faculty_Schedule_Timetable [Name],[Mobile No],[Message]";

sql = sql + " values ( '" + (DGV_Fac_SMS.Rows[i].Cells[0].Value.ToString()) + "', '" + (DGV_Fac_SMS.Rows[i].Cells[1].Value.ToString()) + "','" + (DGV_Fac_SMS.Rows[i].Cells[2].Value.ToString()) + "')";





正确并告诉我们是否有帮助。

谢谢...



Correct and let us know it helped or not.
Thanks...


这篇关于插入查询错误在插入sql语句时显示语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 09:51