Best way to add, update, and delete a database [* Resolved *]
Hello,
I have a database application and have been experiencing problems adding, updating, and deleting using the data table.
Is there a more efficient and robust way to do this. My code l have used is listed below. Someone told me it is better to use the dataset rather than the datatable. If this is so would it be possible to convert the below code to using the dataset. I am not sure on how to use the syntax.
Code:
cnnTeacher.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\IBS Library System\LibrarySystem.mdbersist Security Info=False";
OleDbDataAdapter daTeacher = new OleDbDataAdapter("SELECT * FROM Teacher",cnnTeacher);
OleDbCommandBuilder cbTeacher = new OleDbCommandBuilder(daTeacher);
daTeacher.Fill(dtTeacher);
DataRow drNewTeacher = dtTeacher.NewRow();
drNewTeacher["TeacherID"] = txtAddIDNumber.Text;
drNewTeacher["FirstName"] = txtAddFirstName.Text;
drNewTeacher["LastName"] = txtAddLastName.Text;
drNewTeacher["E-mail"] = txtAddEmail.Text;
dtTeacher.Rows.Add(drNewTeacher);
daTeacher.Update(dtTeacher); //Error - Syntax error in INSERT INTO
Many thanks in advance,
Steve