Home All Groups Group Topic Archive Search About

DataAdapter doesn't insert record

Author
21 Nov 2005 2:53 PM
Jed
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());

Author
21 Nov 2005 5:36 PM
W.G. Ryan - MVP
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.
Show quote
"Jed" <jedatu@newsgroups.nospam> wrote in message
news:F7909A72-4A95-49E1-A488-2B588FEA9E4A@microsoft.com...
> 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());
Author
21 Nov 2005 6:40 PM
Jed
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()?

Show quote
"W.G. Ryan - MVP" wrote:

> 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.
> "Jed" <jedatu@newsgroups.nospam> wrote in message
> news:F7909A72-4A95-49E1-A488-2B588FEA9E4A@microsoft.com...
> > 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());
>
>
>
Author
21 Nov 2005 10:08 PM
W.G. Ryan - MVP
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.
Show quote
"Jed" <jedatu@newsgroups.nospam> wrote in message
news:06342FEB-578D-41D2-82CA-B32B4DB4A3F5@microsoft.com...
> 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()?
>
> "W.G. Ryan - MVP" wrote:
>
>> 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.
>> "Jed" <jedatu@newsgroups.nospam> wrote in message
>> news:F7909A72-4A95-49E1-A488-2B588FEA9E4A@microsoft.com...
>> > 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());
>>
>>
>>
Author
22 Nov 2005 3:42 AM
Kevin Yu [MSFT]
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."

AddThis Social Bookmark Button