DataAdapter doesn't insert record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This has got to be dumb question, but I cannot figure it out.

I am using VS2005, .NET 2, SQL Server Express 2005. I have no trouble
reading records, but the updates to not get persisted to the database.

Why won't this code insert a new record in the EventLog table? Any help
would be great!

CondoTrackerDatabaseDataSet.EventLogDataTable table =
this.EventLogTableAdapter.GetData();
//Rows = 1
MessageBox.Show(table.Rows.Count.ToString());
CondoTrackerDatabaseDataSet.EventLogRow logRow = table.NewEventLogRow();
logRow.EventDate = DateTime.Now;
logRow.RoomNumber = roomNumber;
logRow.EventTypeLabel = eventType.ToString();
logRow.LogText = logText;
//Add Row
table.AddEventLogRow(logRow);
//Rows = 2
MessageBox.Show(table.Rows.Count.ToString());
//Supposedly commits to database
this.EventLogTableAdapter.Update(table);
//Refill table
this.EventLogTableAdapter.ClearBeforeFill = true;
this.EventLogTableAdapter.Fill(table);
//Rows = 1
MessageBox.Show(table.Rows.Count.ToString());
 
From the looks of your code, calling HasChanges right before the Update
should return true (just double check it to be sure). The problem is most
likely in your insert statement, double check the code you have for it and
make sure everything looks right - if that doesn't turn up anything, check
with Sql Profiler and see if anything is being sent back tot he db and if
so, what that is.
 
Thanks for the reply.

Well, the only HasChanges method I see is on the DataSet. However,
table.DataSet == null. Should the DataSet property be populated as a result
of GetData()?
 
Jed - DataSet is the object with HasChanges but if you have a DataTable that
wasn't added to a dataset, tehn it will be null. I don't think this is the
problem though - b/c I think the changes are there, I mentioned it mainly
for the sake of being thorough.
 
Yes, Jed. The simplest way, I think , is to use SQL profiler to check the
insert statement that has been submitted to the SQL server to see what has
been missed.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top