السلام عليكم ورحمة الله
I've the following code
i've Access db in 2 tables
t1&t2 which has a relation in the column patientNo
the code run successfuly and insert data into first table
but when trying to enter data to second table it throw Exception
Syntax error in INSERT INTO statement
.
Here is the code
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb");
ds =new DataSet();
t1DataAdapter = new OleDbDataAdapter(new OleDbCommand("SELECT * FROM t1", con));
t1Command = new OleDbCommandBuilder(t1DataAdapter);
t1DataAdapter.FillSchema(ds, SchemaType.Source);
pTable = ds.Tables["Table"];
pTable.TableName = "t1";
t2DataAdapter=new OleDbDataAdapter(new OleDbCommand("Select * From t2",con));
t2Command=new OleDbCommandBuilder(t2DataAdapter);
t2DataAdapter.FillSchema(ds,SchemaType.Source);
pTable = ds.Tables["Table"];
pTable.TableName = "t2";
ds.Relations.Add(new DataRelation("Pnumber",ds.Tables["t1"].Columns["patientNo"],ds.Tables["t2"].Columns["patientNo"]));
rowT1=ds.Tables["t1"].NewRow();
rowT1["patientNo"]="15";
rowT1["pName"]="Mohamed Mohamed";
rowT1["age"]="22";
rowT1["address"]="Home";
ds.Tables["t1"].Rows.Add(rowT1);
rowT2=ds.Tables["t2"].NewRow();
rowT2["grade"]="very Good";
rowT2["year"]="2007";
rowT2.SetParentRow(rowT1);
ds.Tables["t2"].Rows.Add(rowT2);
t1DataAdapter.Update(ds,"t1");
t2DataAdapter.Update(ds,"t2");
con.Close();I 've tried the same code but with only one table and it run
successfuly but in 2 tables it doesn't
plz help me for determining where the error
and if there another way to insert into
multiple tables in the DataSet
plz tell us
Thank You