Hello All,

This is my first post here but after reading and trying for a couple of days now i figured i might just ask whether what i'm trying to do is possible..........

I have written the code below to check for changes in fields and i want to update those changes to the database but somehow it won't get done.

The code runs without any errors but the data is not saved in the end.

Can anyone help me out with this puzzle as it's driving me crazy........


Thanks in advance,

Kind regards,

Rutger

Public Sub CheckChanges()
        Dim cb As SqlClient.SqlCommandBuilder
        Dim Patent As String
        Patent = Me.tbx_patentnr.Text

        cmd = New SqlCommand("Select * FROM tbl_patents where patentnr = '" & Patent & "' ", con)
        If con.State = ConnectionState.Closed Then con.Open()

        myDA = New SqlDataAdapter(cmd)
        myDataSet = New DataSet()
        myDA.Fill(myDataSet, "Patent")

        Dim ctl As Control
        Dim tbx As String
        Dim kolom As String
        Dim cnt As Integer

        Dim count As Integer = Me.TabControl1.Controls.Count

        If myDataSet.Tables("Patent").Rows.Count > 0 Then

            For i = 0 To myDataSet.Tables("Patent").Columns.Count - 1
                For y = 0 To TabControl1.TabCount - 1
                    kolom = myDataSet.Tables("Patent").Columns(i).ColumnName
                    For Each ctl In Me.TabControl1.TabPages(y).Controls
                        If (TypeOf ctl Is TextBox) Then
                            tbx = ctl.Name
                            tbx = Microsoft.VisualBasic.Right(tbx, (Len(tbx) - 4))
                            If LCase(kolom) = LCase(tbx) Then
                                If ctl.Text <> myDataSet.Tables("Patent").Rows(0).Item(i).ToString Then
                                    cnt = cnt + 1
                                End If
                            End If
                        End If
                    Next
                Next
            Next

            If cnt > 0 Then
                If MsgBox("Do you want to save your changes?", MsgBoxStyle.YesNo, "Save changes?") = MsgBoxResult.Yes Then
                    myDA.TableMappings.Add("Table", "Patent")


                    For i = 0 To myDataSet.Tables("Patent").Columns.Count - 1
                        For y = 0 To TabControl1.TabCount - 1
                            kolom = myDataSet.Tables("Patent").Columns(i).ColumnName
                            For Each ctl In Me.TabControl1.TabPages(y).Controls
                                If (TypeOf ctl Is TextBox) Then
                                    tbx = ctl.Name
                                    tbx = Microsoft.VisualBasic.Right(tbx, (Len(tbx) - 4))
                                    If LCase(kolom) = LCase(tbx) Then
                                        If ctl.Text <> myDataSet.Tables("Patent").Rows(0).Item(i).ToString Then
                                            myDataSet.Tables("Patent").Rows(0).Item(i) = ctl.Text
                                        End If
                                    End If
                                End If
                            Next
                        Next
                    Next
                    cb = New SqlClient.SqlCommandBuilder(myDA)
                    myDA.UpdateCommand = cb.GetUpdateCommand
                End If

                myDA.Update(myDataSet)
                myDataSet.AcceptChanges()

            End If
        End If
    End Sub

Hmmmmmm,
Think i've solved this by myself.... Actually nothing wrong with the code.
The problem was that i had DataDirectory in my connectionstring while the database that i view in my database explorer is linked to my Projects folder directly....

Learning and learning every minute.... ;)

Greetz,

Rutger

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.