sqldataadpater wizard code

M

Mark Kurten

i used the sqldataadapter wizard to generate the following insert statement
"
("INSERT INTO Company(Code, Name, Address1, Address2, Address3, Address4,
BEGINDT, " & _

"BegCheck#, EndCheck#, CancelDate, InsType, STATE) VALUES (@Code, @Name,
@Address" & _

"1, @Address2, @Address3, @Address4, @BEGINDT, @BegCheck#, @EndCheck#,
@CancelDat" & _

"e, @InsType, @STATE); SELECT Code, Name, Address1, Address2, Address3,
Address4," & _

" BEGINDT, BegCheck#, EndCheck#, CancelDate, InsType, STATE FROM Company
WHERE (C" & _

"ode = @Code)")

"

My question is, why is there a select statement included with the insert
statement?

thanks.
 
W

William Ryan eMVP

When you are configuring your adapter, you have the Refresh DataSet option
on which generates this for you...it helps to keep things like Identity
values in Sync and the like.

Just reconfigure your adatper and when you get to the SQL Builder section,
go to Advanced OPtions and uncheck Refresh DataSet (it's the one on the
bottom) if you don't want this in there.

HTH,

Bill
 
K

Kevin Yu [MSFT]

Thanks for Bill's quick response.

Hi Mark,

Thank you for posting in the community!

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know why there is a SELECT
statement follows the INSERT statement in the SqlDataAdapter wizard
generated code. If there is any misunderstanding, please feel free to let
me know.

Just as Bill mentioned, if you have selected Refresh DataSet in the
Advanced Options, it will add a SELECT statement to the INSERT command. We
need to refresh the DataSet because sometimes the inserted value record is
slight different from the value in the DataSet. For example, there is an
auto-increment column in the DataSet. As the auto-increment value is auto
generated in the database table, the real inserted value might be different
from the value originally generated in the DataSet. So to keep the data in
the DataSet up-to-date, we need to synchronize them. Then an SELECT
statement is added.

Does this answer your question? If anything is unclear, please feel free to
reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
M

Mark Kurten

thanks for the help, I just wanted to make sure that the select statement
wasn't a required part..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top