data adapter and sqlcommand

  • Thread starter Thread starter Agnes
  • Start date Start date
A

Agnes

I am confused about these two things
1st)As form load I new a data adapter programmicaly , and I can use stored
procedure to 'select sth ' and then fill into the dataset.by using binding
context, my form can display the correct data.
2nd) I want to new a record, so. dsinvocie.addnew(), I can type the new
data.
3rd) I want to use the store procedure to insert this new record.

my store procedure runs very well [I use SQL analyzer to test it]
However, as i rund daInvoice.udpate(dsInvoice,"invoice") <-- it return
error, it said I didn't delcare update command.
I am confuse that [I only want to insert the data but not update], Do i need
to declare another 'update command (store procedure ) ???]

For some textbox, It said, I can use cmd.Exectuenonquery() to process my
insert command. but not using adapter.
I am really confused. Please help.
Thanks a lot
From Agnes
 
More, Can I use cmdInsert.executenonquery only
but not daInvoice.udpate(dsInvoice,"invoice")
dsInvoice.acceptchanges ???

However, some TextBOOK(not textbox) said adapter check the concurrency very
well.
From Agnes
 
Hi Agnes,

First of all forget the stored procedure a while and until the moment, that
you have all things ready, converting a simple select to a stored procedure
is very easy and now you are mixing up code. At this moment the stored
procedure does not give you any advantages, until it is ready for
production.

My previous answer was (because I did not see what you where doing) for the
direct update of a row.

With a datadapter you have to configure that dataadapter what is very easy
and than do the update command.

Doing this you do not need to add the parameters before the update however
you have to do it before the select, where you only need the fields in the
where part of the clause as parameters.

Basicly
dim da as new SQLDataadapter("SelectionString", Connection)
dim cmb as new SQLCommandbuilder(da)
if mydataset has changes then
da.update(mydataset)
end if

I hope this helps?

Cor
 
Thanks Again.~ I will concentrate on adapter first.
Does it meand i need to fill in cmb ?
cmb.insertcommand, cmd.updatecommand,cmddeletecommand ?
From Agnes
 
Hi Agnes,

That commandbuilder builds the commands automaticly, however it has bugs
with very much fields or complex select statements is told, so you would be
very good test your programs using it. However for a first start it is very
good usable and when you have errors you can starting to make your own
insert, delete and update commands.

I hope this helps

Cor
 
Back
Top