iv'e got an assignment witch requires me to update the northwind database , iv'e done every thing like the tutorials say as follows
i fill The DataTable Using The DataAdapter.Fill(table);
i build the Delete,Insert,Update Commands using CommangBuilder
SqlDataAdapter adapter = new SqlDataAdapter(selectStr, conn);
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
adapter.DeleteCommand = builder.GetDeleteCommand(true);
adapter.UpdateCommand = builder.GetUpdateCommand(true);
adapter.InsertCommand = builder.GetInsertCommand(true);
adapter.Fill(employees_table);
i also set a primary key for the table :
DataColumn[] employees_keys = new DataColumn[2];
employees_keys[0] = employees.Columns["EmployeeID"];
employees_table.PrimaryKey = employees_keys;
now iv'e attempted to delete and add a row :
DataRow row = ConvertEmployeeToRow(employeeToAdd);
employee_table.Rows.Add(row);`
and deleting a row :
DataRow row = employees.Rows.Find(employeeToDismiss.ID);
employees.Rows.Remove(row);
i should also point out that iv'e attempted to use row.SetAdded() and row.Delete()
any ways at the end when i try to update the database
int k = employees_adapter.Update(employees_table);
on added rows sometimes k get valued , on remove never , and in either case nothing really gets updated at all in the data base it self .
any insight of what i'm doing wrong would be most appreciated.