Cannot Update Multiple Tables(Set of useful functions)

asim123_pk

New member
Joined
Dec 2, 2004
Messages
2
Hi !
I am trying to make some functions that will allow me to create ,update , add and delete the dataset easily
But i cannot not close the dataset and use it to fill again . it gives me error

Code:
Missing the DataColumn Username in the DataTable MT for the SourceColumn Username.

Below are the functions i am using

Code:
Dim das As New DataSet 
                das = Ds(das, _SQLConnectStringProperties.ToString, _ 
                "Select * from Friends Where UserID=" & fun1 & " AND FriendID=" & lun1 & "") 
               
Dim values As String = "AUTH=1,Message=" & String.Empty 
                        UpdateDS(das, values) Works here 
                        DataSetClose() 
                        das.Dispose() 



 Dim das1 As New DataSet 
                        das1 = Ds(das1, _SQLConnectStringProperties.ToString, _ 
                        "Select * from Friends Where UserID=" & GetIDByUsername(lun) & " AND FriendID=" & GetIDByUsername(fun) & "") 
                        
Dim values1 As String = "AUTH=1,Message=" & String.Empty 
                                UpdateDS(das1, values1)  Error here





Code:
Private Function Ds(ByVal dataSet As DataSet, ByVal connection As String, ByVal query As String) As DataSet 

            
                SQLconn = New SqlConnection(connection) 
                SQLadapter = New SqlDataAdapter 
                SQLadapter.SelectCommand = New SqlCommand(query, SQLconn) 
                SQLadapter.Fill(dataSet, "MT") 
                SQLCommandBuild = New SqlCommandBuilder(SQLadapter) 
                Return dataSet 


        End Function 



   Private Function DataSetClose() 
            Try 
             
            SQLCommandBuild.Dispose() 
            SQLadapter.Dispose() 
            SQLconn.Dispose() 
            SQLCommandBuild = Nothing 
            SQLadapter = Nothing 
            SQLconn = Nothing 
            Catch ex As Exception 

            End Try 
        End Function 

  Private Function UpdateDS(ByVal DataSet As DataSet, ByVal values As String) 



            Dim dr = DataSet.Tables("MT").Rows(0) 

            Dim keys As String() = values.Split(",") 
            Dim k As Integer = 0 
            For k = 0 To UBound(keys) 
                If keys(k) <> "" Then 

                    Dim key As String() = keys(k).Split("=") 

                    dr.Item(key(0).ToString) = key(1).ToString 

                End If 
            Next 

            SQLadapter.Update(DataSet, "MT") 

        End Function
 
Back
Top