Save to Database using dataset

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mafaisal
    New Member
    • Sep 2007
    • 142

    Save to Database using dataset

    Hello
    I am Using vb.net 2005 And sql2005
    Please see then code below
    Code:
    Public Sub Saving(ByVal Table As String, ByVal Fields As String, ByVal Values As String)
            Dim DsS As New DataSet
            Dim cmd1 As New OleDbCommand(" Select * From " & Table & " Where 1 =2 ", Con)
            'Dim cmd1 As New OleDbCommand(" Insert into Users Select * From Users Where 1=2 ", Con)
            Dap = New OleDbDataAdapter(cmd1)
            Dap.Fill(DsS, Table)
            Dim DrS As DataRow = DsS.Tables(Table).NewRow
            Dim F = Split(Fields, ",")
            Dim V = Split(Values, ",")
            For i As Integer = 0 To UBound(F)
                DrS.Item(F(i)) = V(i)
            Next
    
            DsS.Tables(Table).Rows.Add(DrS)
            DrS.AcceptChanges()
            Dap.Update(DsS, Table)
            DsS.AcceptChanges()
            MsgBox("ADDED")
    
        End Sub
    In the above code there is no error but there is no affect in database
    Please give me Reply
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    To update the database itself you need to add this line after creating dataAdpter :

    e.g.

    Code:
     Dap = New OleDbDataAdapter(cmd1)
       Dim cb As New OleDb.OleDbCommandBuilder(Dap)

    Originally posted by mafaisal
    Hello
    I am Using vb.net 2005 And sql2005
    Please see then code below
    Code:
    Public Sub Saving(ByVal Table As String, ByVal Fields As String, ByVal Values As String)
            Dim DsS As New DataSet
            Dim cmd1 As New OleDbCommand(" Select * From " & Table & " Where 1 =2 ", Con)
            'Dim cmd1 As New OleDbCommand(" Insert into Users Select * From Users Where 1=2 ", Con)
            Dap = New OleDbDataAdapter(cmd1)
            Dap.Fill(DsS, Table)
            Dim DrS As DataRow = DsS.Tables(Table).NewRow
            Dim F = Split(Fields, ",")
            Dim V = Split(Values, ",")
            For i As Integer = 0 To UBound(F)
                DrS.Item(F(i)) = V(i)
            Next
    
            DsS.Tables(Table).Rows.Add(DrS)
            DrS.AcceptChanges()
            Dap.Update(DsS, Table)
            DsS.AcceptChanges()
            MsgBox("ADDED")
    
        End Sub
    In the above code there is no error but there is no affect in database
    Please give me Reply

    Comment

    Working...