SIMPLE update from dataset.

M

Mark

Hello all -

I'm really banging my ahead on this one and pulling my
hair out as the functionality is simple to do but for
some reason, I can't get my code to work. What I'm
attempting to do is pull data in from a text file into a
dataset and then take that dataset and update the
database through a separate dataadapter that is linked to
the db. My code is below. Any suggestions on things
that could be out of place are appreciated.

Much thanks,
Mark

Dim sConnectionString As String

sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=C:/Test;Extended Properties=Text;"

Dim objConn As New System.Data.OleDb.OleDbConnection
(sConnectionString)
objConn.Open()



Dim da As System.Data.OleDb.OleDbDataAdapter = New
OleDbDataAdapter("Select * from OPIROUT.TXT", objConn)
Dim sqlCommandBuilder As OleDb.OleDbCommandBuilder = New
OleDb.OleDbCommandBuilder(da)

da.FillSchema(dsDailyIR, SchemaType.Mapped)
da.Fill(dsDailyIR)

'da.Update(dsDailyIR) <------ this is NOT the database
data adapter.

cnSQL.Open()

daDailyIR.Fill(dsDailyIR)
'daDailyIR.Update(dsDailyIR) <----- Do I need to update
here??

cnSQL.Close()
 
C

Carl Mercier

Basically, you want to write every line of the textfile into the
database, right?

This is normal that the lines don't get written into the DB because
the rowstate of the lines is UNCHANGED. .Update() will only write
updated, added or deleted rows to the database. Why should it update
unchanged rows?

I think the RowState property is not readonly (don't quote me on this)
so you can probably loop through the datatable and mark them all as
"added". That way the update will work.

Carl
 

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