I have a database with multiple tables each linked to the other.(Relational Database) I want to Insert Records from my Dataset to Database. First I tried using OledbCommandBuilder but that didn't work, I found out it couldn't work with relational databases. I haven't linked tables within my dataset, they are linked only in the database. What I have is a button named "Commit". When I press that button I want all the modifications in my dataset.datatable to be reflected in the respective database table. I only know how to INSERT, UPDATE, DELETE a single record at a time but that also is a lengthy task as first I have to do this.
CODE IN THE SAVE BUTTON
DataRow dRow = bookDS.Tables["Book"].NewRow();
dRow[0] = Convert.ToInt64(textBookID.Text);
dRow[1] = textBookName.Text;
dRow[2] = textISBN.Text;
and so on (there are 30 columns)
bookDS.Tables["Book"].Rows.Add(dRow);
Then
CODE IN THE COMMIT BUTTON
con.Open();
string sql = "Insert INTO Book Values (@BookId, @BookName, @ISBNNo, @PublicationId, @CategoryId, @Pages,@Price,@Author1,@Author2,@TotalCopies,@IssuedCopies,@AvailableCopies,@SupplierName,@Note)";
OleDbCommand save = new OleDbCommand(sql);
save.Parameters.Add("@BookId", OleDbType.BigInt).Value = Convert.ToInt64(dRow[0]);
save.Parameters.Add("@BookName", OleDbType.BSTR).Value = dRow[1];
save.Parameters.Add("@ISBNNo", OleDbType.BSTR).Value = dRow[2];
and so on...
save.Connection = con; save.ExecuteNonQuery();
con.Close();
That is all i can think of but that only works for a single Row and so I its like I have to press the COMMIT button every time I press the SAVE button.
Can anyone please help me with this ???
P.S : I am using MSAccess and also don't want to use TABLEADAPTER ( I want to do everything with my code )