PC Review


Reply
Thread Tools Rate Thread

DataAdapter doesn't insert record

 
 
=?Utf-8?B?SmVk?=
Guest
Posts: n/a
 
      21st Nov 2005
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());
 
Reply With Quote
 
 
 
 
W.G. Ryan - MVP
Guest
Posts: n/a
 
      21st Nov 2005
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" <(E-Mail Removed)> wrote in message
news:F7909A72-4A95-49E1-A488-(E-Mail Removed)...
> 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());



 
Reply With Quote
 
=?Utf-8?B?SmVk?=
Guest
Posts: n/a
 
      21st Nov 2005
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" <(E-Mail Removed)> wrote in message
> news:F7909A72-4A95-49E1-A488-(E-Mail Removed)...
> > 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());

>
>
>

 
Reply With Quote
 
W.G. Ryan - MVP
Guest
Posts: n/a
 
      21st Nov 2005
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.
"Jed" <(E-Mail Removed)> wrote in message
news:06342FEB-578D-41D2-82CA-(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
>> news:F7909A72-4A95-49E1-A488-(E-Mail Removed)...
>> > 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());

>>
>>
>>



 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      22nd Nov 2005
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."

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataAdapter for Insert BoM Microsoft ADO .NET 1 16th Nov 2006 10:15 PM
Insert from DataAdapter table =?Utf-8?B?RGF2ZSBBLg==?= Microsoft ADO .NET 1 23rd Jun 2004 12:15 PM
Insert from DataAdapter table =?Utf-8?B?RGF2ZSBBLg==?= Microsoft ADO .NET 0 22nd Jun 2004 08:56 PM
DataAdapter insert ... Lloyd Dupont Microsoft ADO .NET 1 25th Feb 2004 08:38 AM
insert IF record doesn't exist Julia Lerman Microsoft Access Queries 1 29th Aug 2003 09:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:29 AM.