string s1= string.Empty; 
            string s2= string.Empty; 
            string s3= string.Empty; 
            string s4= string.Empty; 
            string s5= string.Empty; 
            string s6= string.Empty;
            string s7 = string.Empty;
            string s8 = string.Empty;
  string[] data =null;
                string[] data1 = null;
                data = File.ReadAllLines(@"1.txt", Encoding.Default);
                
               
               for (int i= 0;i<data.Length;i++)
                {
                    data1 = data[i].Split(char1);
                   
                   
                    s1 = data1[0];
                    s2 = data1[1];
                    s3 = data1[2];
                    s4 = data1[3];
                    s5 = data1[4];
                    s6 = data1[5];
                    s7 = data1[6];
                    s8 = data1[7];                    //string strinsert = "INSERT INTO Electricity (Department,AmmeterCode,CentralCode,High,Low,Level,CurrentAmount,Data) values('" + s1 + "','" + s2 + "','" + s3 + "','" + s4 + "','" + s5 + "','" + s6 + "','" + s7 + "','" + s8 + "')";
                    string strinsert = "insert into Electricity (Department,AmmeterCode,CentralCode,High,Low,Level,CurrentAmount,Data) values(" + s1 + "," + s2 + "," + s3 + "," + s4 + "," + s5 + "," + s6 + "," + s7 + "," + s8 + ")";
                                                       OleDbCommand cmd = new OleDbCommand(strinsert, conn);
                 
                                      
                    cmd.ExecuteNonQuery();                                  }
            }
            catch (Exception ex) 
            {
                
            }报错:INSERT INTO 语句语法错误 
哪里错了???????????????????????????????????????

解决方案 »

  1.   

    ACCESS数据库有没有在数据库执行SQL语句的地方啊  那样就好检查SQL语句了
      

  2.   

    数据类型不对把...  如果数据库字段是char varchar ntext需要''你这样写SQL语句很累的 
    建议使用SqlParameter 来传递参数
      

  3.   

    看看你的数据类型是不是对应的
    Department,AmmeterCode,CentralCode,High,Low,Level,CurrentAmount,Data
    s1 s2 s3 s4 s5 s6 s7 s8 
      

  4.   

    设置断点 将strinsert的值 在数据库中运行 看什么地方出错 
      

  5.   


      string strinsert = "insert into Electricity (Department,AmmeterCode,CentralCode,High,Low,Level,CurrentAmount,Data) values(" + s1 + "," + s2 + "," + s3 + "," + s4 + "," + s5 + "," + s6 + "," + s7 + "," + s8 + ")"; 数据类型都没有转换,你就直接这么插进去了?
      

  6.   

    string strinsert = "insert into Electricity (Department,AmmeterCode,CentralCode,High,Low,Level,CurrentAmount,Data) values(" + s1 + "," + s2 + "," + s3 + "," + s4 + "," + s5 + "," + s6 + "," + s7 + "," + s8 + ")"; 
    改为
    string strinsert = "insert into Electricity (Department,AmmeterCode,CentralCode,High,Low,Level,CurrentAmount,Data) values('" + s1 + "','" + s2 + "','" + s3 + "','" + s4 + "','" + s5 + "','" + s6 + "','" + s7 + "','" + s8 + "')"; 
      

  7.   

    怎样在ACCESS中执行strinsert????  找不到啊accesss数据库字段类型全都改成文本类型了  还是不行啊
      

  8.   

    怎么看怎么觉的“号的个数不太对,用下面的实验下:string strinsert = "insert into Electricity (Department,AmmeterCode,CentralCode,High,Low,Level,CurrentAmount,Data) values(s1 + "," + s2 + "," + s3 + "," + s4 + "," + s5 + "," + s6 + "," + s7 + "," + s8)";            
      

  9.   

    ACCESS要注意字段名尽量别用保留的关键字,否则也会语法错误的
      

  10.   

    "insert into Electricity (Department,AmmeterCode,CentralCode,High,Low,Level,CurrentAmount,Data) values(" + s1 + "," + s2 + "," + s3 + "," + s4 + "," + s5 + "," + s6 + "," + s7 + "," + s8 + ")"; Data--Date
    难道是这。
      

  11.   


    string strinsert = "insert into Electricity (Department,AmmeterCode,CentralCode,High,Low,Level,CurrentAmount,Data) values('" + s1 + "','" + s2 + "','" + s3 + "','" + s4 + "','" + s5 + "','" + s6 + "','" + s7 + "','" + s8 + "')";
    试下上面的吧,,你的没有单引号。
      

  12.   


    string strinsert = string.Formate(
    "insert into Electricity (Department,AmmeterCode,CentralCode,High,Low,Level,CurrentAmount,Data)
     values
    ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')",
    s1,s2,s3,s4,s5,s6,s7,s8)
      

  13.   

    把你表里的字段去不设置为string看看
      

  14.   

    access里可以执行sql命令的,设置断点,取出sql语句,
    然后放到access里执行一下。
      

  15.   

    到查询分析器中执行下,修改错误吧。还有楼主这样拼接累不??我的博客 程序员日记 http://www.ideaext.com 欢迎交流