Newbie Add Row Question

P

phenderson

Hi,

I'm fairly new to vb/ado.net and am having a hard time adding a row to
a table. The following code executes without any exceptions, but the
rows do not appear in the database. Also, I've stepped through the
entire thing and the RowState property never changes from "detached".
Any help would be greatly appreciated!

--------------------------------------------------------------------------------------------------------------------
Dim retList as array
Dim strArray as Object
Dim i as Integer
Dim cnConn As New SqlConnection
Dim da As SqlDataAdapter
Dim ds As DataSet
Dim dt As DataTable
Dim dr As DataRow
Dim drc As DataRowCollection

cnConn.ConnectionString = _
"Data Source=" & strServer & ";" & _
"Initial Catalog=" & strDatabase & ";" & _
"Integrated Security=SSPI"

cnConn.Open()

da = New SqlDataAdapter("select * from tProviders", cnConn)
ds = New DataSet("tProviders")
da.Fill(ds, "tProviders")

dt = New DataTable
dt = ds.Tables("tProviders")
drc = dt.Rows

For i = (LBound(retList) + 1) To UBound(retList)

strArray = Split(retList(i), "^")

dr = dt.NewRow

drc.Add(strArray)

Next
--------------------------------------------------------------------------------------------------------------------
 
S

Stacey

Datasets and datatables are detached. Adding to those do not do anything.
You need to write this data back to the database. There are several methods
to this. The Data adapter can do this for you. Look into CurrencyManager
(yes.. weird name)..
 

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