PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET How can I use InsertCommand, UpdateCommand?

Reply

How can I use InsertCommand, UpdateCommand?

 
Thread Tools Rate Thread
Old 08-02-2006, 01:35 PM   #1
Doru Roman
Guest
 
Posts: n/a
Default How can I use InsertCommand, UpdateCommand?


Hi,
I am new to .NET and I created a data adapter which generated the
SelectCommnad, UpdateCommand, DeleteCommand and InsertCommand through the
wizard. But what do I do with them? How do I use them, what are the methods
to trigger an Insert, a Select, an Update or a Delete? Can someone explain
to me?
Also is DataReader the only way of retrieving the result of a Select query?
Is ExecuteNonQuery the only way to make an update, delete or insert?
Thanks,
Doru


  Reply With Quote
Old 08-02-2006, 02:03 PM   #2
W.G. Ryan - MVP
Guest
 
Posts: n/a
Default Re: How can I use InsertCommand, UpdateCommand?


"Doru Roman" <doruroman@rogers.com> wrote in message
news:eHG25RLLGHA.2704@TK2MSFTNGP15.phx.gbl...
> Hi,
> I am new to .NET and I created a data adapter which generated the
> SelectCommnad, UpdateCommand, DeleteCommand and InsertCommand through the
> wizard. But what do I do with them?

Call the .Update method of your dataadapter passing in the datatable you've
been editing ie

MyDataAdapter.Update(MydataTable);
How do I use them, what are the methods
> to trigger an Insert, a Select, an Update or a Delete? Can someone explain
> to me?

When you edit a dataTable and call Update on an adapter, it looks at the
Rowstate of each row. If the Rowstate is deleted, it uses the values
configured and calls your delete command. If its inserted, the same but with
an Insert command. this should explain the process a little more in depth
http://www.knowdotnet.com/articles/datasetmerge.html

> Also is DataReader the only way of retrieving the result of a Select
> query?

No. A dataAdapter opens a connection (unless you do it manually), gets the
data and loads it into your dataset/datatable and then closes the
connection. The dataReader requires you to do all the work. there are a
few other nuances but that's close enough to get the idea.
> Is ExecuteNonQuery the only way to make an update, delete or insert?

--No, but it's probably the most logical and straightforward.
> Thanks,
> Doru
>



  Reply With Quote
Old 08-02-2006, 02:30 PM   #3
Doru Roman
Guest
 
Posts: n/a
Default Re: How can I use InsertCommand, UpdateCommand?

Thanks, W.G. Now it makes sense for me.


  Reply With Quote
Old 08-02-2006, 07:01 PM   #4
W.G. Ryan - MVP
Guest
 
Posts: n/a
Default Re: How can I use InsertCommand, UpdateCommand?

Great. I know it's a little hard to understand at first but once you get
your arms around it, it's actually pretty straightforward and you can work
your way through most problems pretty easily. If you have any more issues,
please don't hesitate to ask ;-)
"Doru Roman" <doruroman@rogers.com> wrote in message
news:OajQCxLLGHA.2812@TK2MSFTNGP14.phx.gbl...
> Thanks, W.G. Now it makes sense for me.
>



  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off