Changes to dataset, update database, programatically?

jinjouk

New member
Joined
May 14, 2008
Messages
3
Programming Experience
1-3
Hi, I have a dataset populated with a data adapter connected to sql server.

I am trying to modify a row without using a user interface.

so far i have:
VB.NET:
 For Each row As DataRow In ds.Tables(0).Rows
            If row.Item("segment") = segment Then
                If row.Item("Active") = False Then
                    row.BeginEdit()
                    row.Item("Active") = True
                    row.EndEdit()
                    da.Update(ds)
                End If
            End If
        Next

but I get an error: System.Data.SqlClient.SqlException : Line 1: Incorrect syntax near '('.

my update command is as follows:
VB.NET:
Dim selectCommand As New SqlCommand
        selectCommand.Connection = jobDatabase.Connection
        selectCommand.CommandText = "SELECT * FROM " & SegmentTable

        Dim updateCommand As New SqlCommand
        updateCommand.Connection = jobDatabase.Connection

        updateCommand.Parameters.Add("@segment", SqlDbType.VarChar, 50)

        updateCommand.Parameters.Add("@Active", SqlDbType.Bit)
        updateCommand.CommandText = "UPDATE " & SegmentTable & " SET (Active = @Active) WHERE segment = @segment"

        da.SelectCommand = selectCommand
        da.UpdateCommand = updateCommand

modifying some of the editing code i get no errors but database doesnt reflect updates and I cant remember what I did but it must have been wrong anyway.

Can anyone tell me what I'm doing wrong?

thanks
 
Back
Top