A
AnandVishy
I wrote a program that inserts records into a table in a MS Access
database. For some reason, it works only for tables without spaces in
their names:
There are four tables: "test 1" "test2" "test 3" and "test4" each with
fields word, pos, and meaning.
The following code works only for test2 and test4, the tables whose
names do not contain any spaces.
string tableName="test 1"; //place table name here
OleDbConnection conn=new
OleDbConnection("provider=microsoft.jet.oledb.4.0;data
source=lists.mdb");
OleDbDataAdapter da=new OleDbDataAdapter("select * from
["+tableName+"]",conn);
OleDbCommandBuilder cb=new OleDbCommandBuilder(da);
DataSet ds=new DataSet();
da.Fill(ds);
conn.Close();
DataTable dt=ds.Tables[0];
DataRow dr=dt.NewRow();
dr["word"]="myword";
dr["pos"]="mypos";
dr["meaning"]="mymeaning";
dt.Rows.Add(dr);
try
{
da.Update(ds);
}
catch(OleDbException ole){Console.WriteLine(ole.Message);}
database. For some reason, it works only for tables without spaces in
their names:
There are four tables: "test 1" "test2" "test 3" and "test4" each with
fields word, pos, and meaning.
The following code works only for test2 and test4, the tables whose
names do not contain any spaces.
string tableName="test 1"; //place table name here
OleDbConnection conn=new
OleDbConnection("provider=microsoft.jet.oledb.4.0;data
source=lists.mdb");
OleDbDataAdapter da=new OleDbDataAdapter("select * from
["+tableName+"]",conn);
OleDbCommandBuilder cb=new OleDbCommandBuilder(da);
DataSet ds=new DataSet();
da.Fill(ds);
conn.Close();
DataTable dt=ds.Tables[0];
DataRow dr=dt.NewRow();
dr["word"]="myword";
dr["pos"]="mypos";
dr["meaning"]="mymeaning";
dt.Rows.Add(dr);
try
{
da.Update(ds);
}
catch(OleDbException ole){Console.WriteLine(ole.Message);}