PC Review


Reply
Thread Tools Rate Thread

Clear a datatable before inserting new records

 
 
JamesT
Guest
Posts: n/a
 
      7th Nov 2008
Is there an easy way of clearing one datatable in a dataset and hence the
database table to no records?

I have a large dataset that contains many datatables. Most of the datatables
are updated using linked forms but a couple are not updated using forms as
the data they contain is too variable. I would like to clear the datatable
and then insert new records from scratch from classes I have defined. I
cannot find a method to clear the datatable except row by row. Inserting the
new data and updating the database I can do OK. Have I missed something? If
you supply any code could it be in VB.NET please.
--
JamesT
 
Reply With Quote
 
 
 
 
Miha Markic
Guest
Posts: n/a
 
      7th Nov 2008
table.Rows.Clear() perhaps?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"JamesT" <(E-Mail Removed)> wrote in message
news:CDEA3561-49F1-47E2-AF5E-(E-Mail Removed)...
> Is there an easy way of clearing one datatable in a dataset and hence the
> database table to no records?
>
> I have a large dataset that contains many datatables. Most of the
> datatables
> are updated using linked forms but a couple are not updated using forms as
> the data they contain is too variable. I would like to clear the datatable
> and then insert new records from scratch from classes I have defined. I
> cannot find a method to clear the datatable except row by row. Inserting
> the
> new data and updating the database I can do OK. Have I missed something?
> If
> you supply any code could it be in VB.NET please.
> --
> JamesT


 
Reply With Quote
 
JamesT
Guest
Posts: n/a
 
      7th Nov 2008
Thanks I will try that. I was looking at the tableadapter commands - no
wonder I was lost.
--
JamesT


"Miha Markic" wrote:

> table.Rows.Clear() perhaps?
>
> --
> Miha Markic [MVP C#, INETA Country Leader for Slovenia]
> RightHand .NET consulting & development www.rthand.com
> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>
> "JamesT" <(E-Mail Removed)> wrote in message
> news:CDEA3561-49F1-47E2-AF5E-(E-Mail Removed)...
> > Is there an easy way of clearing one datatable in a dataset and hence the
> > database table to no records?
> >
> > I have a large dataset that contains many datatables. Most of the
> > datatables
> > are updated using linked forms but a couple are not updated using forms as
> > the data they contain is too variable. I would like to clear the datatable
> > and then insert new records from scratch from classes I have defined. I
> > cannot find a method to clear the datatable except row by row. Inserting
> > the
> > new data and updating the database I can do OK. Have I missed something?
> > If
> > you supply any code could it be in VB.NET please.
> > --
> > JamesT

>
>

 
Reply With Quote
 
Miha Markic
Guest
Posts: n/a
 
      7th Nov 2008
Hi James,

Perhaps a clarification to avoid misunderstandings.
table.Rows.Clear() will clear datatable in memory. It won't affect database
in any way.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"JamesT" <(E-Mail Removed)> wrote in message
news:E06FAF67-BC25-4C25-AC18-(E-Mail Removed)...
> Thanks I will try that. I was looking at the tableadapter commands - no
> wonder I was lost.
> --
> JamesT
>
>
> "Miha Markic" wrote:
>
>> table.Rows.Clear() perhaps?
>>
>> --
>> Miha Markic [MVP C#, INETA Country Leader for Slovenia]
>> RightHand .NET consulting & development www.rthand.com
>> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>>
>> "JamesT" <(E-Mail Removed)> wrote in message
>> news:CDEA3561-49F1-47E2-AF5E-(E-Mail Removed)...
>> > Is there an easy way of clearing one datatable in a dataset and hence
>> > the
>> > database table to no records?
>> >
>> > I have a large dataset that contains many datatables. Most of the
>> > datatables
>> > are updated using linked forms but a couple are not updated using forms
>> > as
>> > the data they contain is too variable. I would like to clear the
>> > datatable
>> > and then insert new records from scratch from classes I have defined. I
>> > cannot find a method to clear the datatable except row by row.
>> > Inserting
>> > the
>> > new data and updating the database I can do OK. Have I missed
>> > something?
>> > If
>> > you supply any code could it be in VB.NET please.
>> > --
>> > JamesT

>>
>>


 
Reply With Quote
 
JamesT
Guest
Posts: n/a
 
      7th Nov 2008
Do I need to do an update to the database with the cleared datatable before I
add new rows and then update again after adding the rows?

I am only just starting to use ADO.NET after many years of using ADODB even
with .NET. I thought it was time I started using the 'new' technology so I am
still on a learning curve. So please be gentle with me.

--
JamesT


"Miha Markic" wrote:

> Hi James,
>
> Perhaps a clarification to avoid misunderstandings.
> table.Rows.Clear() will clear datatable in memory. It won't affect database
> in any way.
>
> --
> Miha Markic [MVP C#, INETA Country Leader for Slovenia]
> RightHand .NET consulting & development www.rthand.com
> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>
> "JamesT" <(E-Mail Removed)> wrote in message
> news:E06FAF67-BC25-4C25-AC18-(E-Mail Removed)...
> > Thanks I will try that. I was looking at the tableadapter commands - no
> > wonder I was lost.
> > --
> > JamesT
> >
> >
> > "Miha Markic" wrote:
> >
> >> table.Rows.Clear() perhaps?
> >>
> >> --
> >> Miha Markic [MVP C#, INETA Country Leader for Slovenia]
> >> RightHand .NET consulting & development www.rthand.com
> >> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
> >>
> >> "JamesT" <(E-Mail Removed)> wrote in message
> >> news:CDEA3561-49F1-47E2-AF5E-(E-Mail Removed)...
> >> > Is there an easy way of clearing one datatable in a dataset and hence
> >> > the
> >> > database table to no records?
> >> >
> >> > I have a large dataset that contains many datatables. Most of the
> >> > datatables
> >> > are updated using linked forms but a couple are not updated using forms
> >> > as
> >> > the data they contain is too variable. I would like to clear the
> >> > datatable
> >> > and then insert new records from scratch from classes I have defined. I
> >> > cannot find a method to clear the datatable except row by row.
> >> > Inserting
> >> > the
> >> > new data and updating the database I can do OK. Have I missed
> >> > something?
> >> > If
> >> > you supply any code could it be in VB.NET please.
> >> > --
> >> > JamesT
> >>
> >>

>
>

 
Reply With Quote
 
William \(Bill\) Vaughn
Guest
Posts: n/a
 
      7th Nov 2008
Well, you might have waited too long.
LINQ to SQL is being ... well, Microsoft is not that thrilled with it and
don't plan to give it much more attention. By some, it's not seen as a
viable approach. Count me among those who don't endorse it.

--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
____________________________________________________________________________________________



"JamesT" <(E-Mail Removed)> wrote in message
news:2C46B039-5DAC-46B5-91E4-(E-Mail Removed)...
> Do I need to do an update to the database with the cleared datatable
> before I
> add new rows and then update again after adding the rows?
>
> I am only just starting to use ADO.NET after many years of using ADODB
> even
> with .NET. I thought it was time I started using the 'new' technology so I
> am
> still on a learning curve. So please be gentle with me.
>
> --
> JamesT
>
>
> "Miha Markic" wrote:
>
>> Hi James,
>>
>> Perhaps a clarification to avoid misunderstandings.
>> table.Rows.Clear() will clear datatable in memory. It won't affect
>> database
>> in any way.
>>
>> --
>> Miha Markic [MVP C#, INETA Country Leader for Slovenia]
>> RightHand .NET consulting & development www.rthand.com
>> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>>
>> "JamesT" <(E-Mail Removed)> wrote in message
>> news:E06FAF67-BC25-4C25-AC18-(E-Mail Removed)...
>> > Thanks I will try that. I was looking at the tableadapter commands - no
>> > wonder I was lost.
>> > --
>> > JamesT
>> >
>> >
>> > "Miha Markic" wrote:
>> >
>> >> table.Rows.Clear() perhaps?
>> >>
>> >> --
>> >> Miha Markic [MVP C#, INETA Country Leader for Slovenia]
>> >> RightHand .NET consulting & development www.rthand.com
>> >> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>> >>
>> >> "JamesT" <(E-Mail Removed)> wrote in message
>> >> news:CDEA3561-49F1-47E2-AF5E-(E-Mail Removed)...
>> >> > Is there an easy way of clearing one datatable in a dataset and
>> >> > hence
>> >> > the
>> >> > database table to no records?
>> >> >
>> >> > I have a large dataset that contains many datatables. Most of the
>> >> > datatables
>> >> > are updated using linked forms but a couple are not updated using
>> >> > forms
>> >> > as
>> >> > the data they contain is too variable. I would like to clear the
>> >> > datatable
>> >> > and then insert new records from scratch from classes I have
>> >> > defined. I
>> >> > cannot find a method to clear the datatable except row by row.
>> >> > Inserting
>> >> > the
>> >> > new data and updating the database I can do OK. Have I missed
>> >> > something?
>> >> > If
>> >> > you supply any code could it be in VB.NET please.
>> >> > --
>> >> > JamesT
>> >>
>> >>

>>
>>

 
Reply With Quote
 
Miha Markic
Guest
Posts: n/a
 
      8th Nov 2008
Hi James,
"JamesT" <(E-Mail Removed)> wrote in message
news:2C46B039-5DAC-46B5-91E4-(E-Mail Removed)...
> Do I need to do an update to the database with the cleared datatable
> before I
> add new rows and then update again after adding the rows?


If you clear rows from datatable then ado.net won't know nothing about them
(it will ignore them because they are not there anymore).
You should clear, add new rows and use adapter.Update to commit changes to
database. The new rows will be marked as Unchanged afterwards (row's
RowState will change from Added to Unchanged)

> I am only just starting to use ADO.NET after many years of using ADODB
> even
> with .NET. I thought it was time I started using the 'new' technology so I
> am
> still on a learning curve. So please be gentle with me.


Sure, no problem. Perhaps you should read a topic about ado.net in .net help
files...
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

 
Reply With Quote
 
Miha Markic
Guest
Posts: n/a
 
      8th Nov 2008
LINQ to SQL? :-P

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"William (Bill) Vaughn" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Well, you might have waited too long.
> LINQ to SQL is being ... well, Microsoft is not that thrilled with it and
> don't plan to give it much more attention. By some, it's not seen as a
> viable approach. Count me among those who don't endorse it.


 
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
Copying records from datatable to datatable in dataset tshad Microsoft C# .NET 1 24th Jun 2008 01:39 AM
Datatable clear inadsad@hotmail.com Microsoft VB .NET 4 1st Jun 2008 07:30 AM
How do you clear a datatable? Tony Girgenti Microsoft ADO .NET 10 18th Mar 2007 11:43 PM
dataTable.Clear() goldie11 Microsoft ADO .NET 7 27th Dec 2006 12:04 PM
datatable.clear darkStar Microsoft VB .NET 0 8th Nov 2005 05:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:31 PM.