Home All Groups Group Topic Archive Search About

Newbie Add Row Question

Author
12 Oct 2006 7:11 PM
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
--------------------------------------------------------------------------------------------------------------------

Author
12 Oct 2006 7:26 PM
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)..
Show quoteHide quote
"phenderson" <paul.m.hender***@gmail.com> wrote in message
news:1160680266.020821.287350@i42g2000cwa.googlegroups.com...
> 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
> --------------------------------------------------------------------------------------------------------------------
>