I am looking for example of reading one table using datareader and updating
another with the values using a dataadapter.

Re: How to read from DataReader and Update using DataAdapter by Jeppe

Jeppe
Thu Mar 10 01:48:42 CST 2005

> I am looking for example of reading one table using datareader and
updating
> another with the values using a dataadapter.

'set up the dataset and adapter
dim con as new sqlconnection(<connectionstring and all that....>)
con.open
dim myAdapter as new sqlDataAdapter("Select * from TableA", con)
dim myDataset as new dataset
myAdapter.fill(myDataset, "TableA")

dim con as new sqlconnection(<connectionstring and all that....>)
dim cmd as new sqlCommand("Select * from TableB", con)
dim myReader as sqlDatareader = cmd.executeReader

while myReader.Read
dim newRow as datarow = myDataset.tables("TableA").Newrow
newRow.beginEdit
newRow("firstname") = myReader("firstname")
newRow("lastname") = myReader("lastname")
newRow.endEdit
myDataset.tables("TableA").Rows.add(newRow)
end while

myAdapter.Update(myDataset, "TableA")
con.close

'remember to cleanup after yourself....

....just off the top of my head... :-)
Jeppe Jespersen




Re: How to read from DataReader and Update using DataAdapter by Sahil

Sahil
Thu Mar 10 06:00:58 CST 2005

You will have to hand-create a DataSet/DataTable per the values of the
DataReader and pass those into DataAdapter - remember the rowstates will be
a major thing to be careful of here.

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/


"Mori" <Mori@discussions.microsoft.com> wrote in message
news:1C253ED8-2DB6-475B-B37A-6D521FA53D8B@microsoft.com...
>I am looking for example of reading one table using datareader and updating
> another with the values using a dataadapter.



Re: How to read from DataReader and Update using DataAdapter by Mori

Mori
Thu Mar 10 06:47:03 CST 2005

Thanks, will this allow me to loop through the datarows and only update
values matching those from the datareader? If the data does not match, then
I need to do an insert.

Thanks

"Jeppe Dige Jespersen" wrote:

> > I am looking for example of reading one table using datareader and
> updating
> > another with the values using a dataadapter.
>
> 'set up the dataset and adapter
> dim con as new sqlconnection(<connectionstring and all that....>)
> con.open
> dim myAdapter as new sqlDataAdapter("Select * from TableA", con)
> dim myDataset as new dataset
> myAdapter.fill(myDataset, "TableA")
>
> dim con as new sqlconnection(<connectionstring and all that....>)
> dim cmd as new sqlCommand("Select * from TableB", con)
> dim myReader as sqlDatareader = cmd.executeReader
>
> while myReader.Read
> dim newRow as datarow = myDataset.tables("TableA").Newrow
> newRow.beginEdit
> newRow("firstname") = myReader("firstname")
> newRow("lastname") = myReader("lastname")
> newRow.endEdit
> myDataset.tables("TableA").Rows.add(newRow)
> end while
>
> myAdapter.Update(myDataset, "TableA")
> con.close
>
> 'remember to cleanup after yourself....
>
> .....just off the top of my head... :-)
> Jeppe Jespersen
>
>
>
>