日期:2014-05-18  浏览次数:20746 次

c# 向access添加行纪录的问题。
请问,为什么我在添加一行到数据库里会出错?

我的access数据库里一个表hashValue.
字段为
userNumber longinteger
inputvector memo  就是备注类型,应为我想在这里存1024个字符.所以不能用character.
i longinteger
t longinteger
Bit characters
Top longinteger
c#代码为
C# code

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;



namespace connectionDB
{
    class Program
    {
        static void Main(string[] args)
        {
            OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Thesis\thesis programming\database\user1.mdb;Jet OLEDB:Engine Type=5");
            cn.Open();
            //OleDbCommand command = cn.CreateCommand();
            OleDbDataAdapter adapter = new OleDbDataAdapter("select userNumber,inputVector,i,t,Bit,Top from hashValue", cn);
            OleDbCommandBuilder comb = new OleDbCommandBuilder(adapter); 
            DataSet ds = new DataSet();
            adapter.Fill(ds, "hashValue");

            DataRow dr = ds.Tables["hashValue"].NewRow();
            dr[0] = 11;
            dr[1] = "1111111";
            dr[2] = 22;
            dr[3] = 33;
            dr[4] = '1';
            dr[5] = 44;
            ds.Tables["hashValue"].Rows.Add();
            adapter.Update(ds, "hashValue"); //[color=#FF0000]这里出错,说  INSERT INTO 语句的语法错误[/color]。



            cn.Close();
            Console.Read();
             
        }
    }
}



------解决方案--------------------
可能是表中字段名与access中的保留关键字重名,会导致问题的
你用这个方式吧[FieldName]
select userNumber,inputVector,i,t,[Bit],[Top] from hashValue