G
Guest
Hello,
I have to read data from an external file into a ado.net table
ds.tblExternal.ReadXml(...)
and I want to load this data into a table that resides in a sql server
(2000) DB. I can do this if I loop through ds.tblExternal and add new rows
to the ado.net table from the DB:
da.Fill(ds, "tblfromDB") '--table from sql DB
Dim dr1 As DataRow
For Each dr As DataRow in ds.tblExternal.Rows
dr1 = ds.Tables("tblFromDB").NewRow
For Each dc As DataColumn in ds.tblExternal.Columns
dr1(dc.ColumnName) = dr(dc.ColumnName)
Next
ds.Tables("tblFromDB").Rows.Add(dr1)
Next
da.Update(ds,"tblFromDB") '--table on sql server DB populates OK here
If I use a dataTableReader to load data from tblExternal to "tblFromDB" I
don't have to do Looping, and this eliminates a lot of lines of code. The
problem is that if I load "tblFromDB" using a dataTableReader, it wont
update/populate the table on the DB end.
Dim reader As DataTableReader = ds.tblExternal.CreateDataReader
ds.Tables("tblFromDB").Load(reader)
da.Update(ds,"tblFromDB") '--doesn't update table on the sql server DB
This won't populate the table on the DB like looping will, however, if I set
a datagrideview.datasource to ds.Tables("tblFromDB") after loading
"tblFromDB" using the dataTableReader, the datagridview will display data
from "tblFromDB". I am guessing that new rows were not added to "tblFromDB"
when loading data using the dataTableReader.
Does anyone know what to do to make the data from the dataTableReader able
to update/populate the table on the sql server end? The goal is to not have
to loop through tables.
Or --- is there a better way to read data from the external file into the
sql server table?
Thanks,
Rich
I have to read data from an external file into a ado.net table
ds.tblExternal.ReadXml(...)
and I want to load this data into a table that resides in a sql server
(2000) DB. I can do this if I loop through ds.tblExternal and add new rows
to the ado.net table from the DB:
da.Fill(ds, "tblfromDB") '--table from sql DB
Dim dr1 As DataRow
For Each dr As DataRow in ds.tblExternal.Rows
dr1 = ds.Tables("tblFromDB").NewRow
For Each dc As DataColumn in ds.tblExternal.Columns
dr1(dc.ColumnName) = dr(dc.ColumnName)
Next
ds.Tables("tblFromDB").Rows.Add(dr1)
Next
da.Update(ds,"tblFromDB") '--table on sql server DB populates OK here
If I use a dataTableReader to load data from tblExternal to "tblFromDB" I
don't have to do Looping, and this eliminates a lot of lines of code. The
problem is that if I load "tblFromDB" using a dataTableReader, it wont
update/populate the table on the DB end.
Dim reader As DataTableReader = ds.tblExternal.CreateDataReader
ds.Tables("tblFromDB").Load(reader)
da.Update(ds,"tblFromDB") '--doesn't update table on the sql server DB
This won't populate the table on the DB like looping will, however, if I set
a datagrideview.datasource to ds.Tables("tblFromDB") after loading
"tblFromDB" using the dataTableReader, the datagridview will display data
from "tblFromDB". I am guessing that new rows were not added to "tblFromDB"
when loading data using the dataTableReader.
Does anyone know what to do to make the data from the dataTableReader able
to update/populate the table on the sql server end? The goal is to not have
to loop through tables.
Or --- is there a better way to read data from the external file into the
sql server table?
Thanks,
Rich