0

this is the code...
I am trying to update a element from login table but it not showing any error massage
or any thing execution is error free but finally whenever i check the database its not
updated.. i'm using access2007 database with vb 2008..
PLEASE Help me..

dbprovider = "Provider=Microsoft.ACE.OLEDB.12.0;"
        dbsource = "Data Source=|DataDirectory|\Ex_m.accdb;" & "Persist Security Info=True;" & "Jet OLEDB:Database Password=123456"
        con.ConnectionString = dbprovider & dbsource
        Dim ds As New DataSet
        con.Open()
        sql = "select * from  System"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "Ex_m")
        If ds.Tables("Ex_m").Rows(0).Item(3) = False Then
            Dim pass1, pass2 As String
            con.Close()
            pass1 = InputBox("Please Enter ADMIN Password")
            pass2 = InputBox("Please Re-enter ADMIN Password")
            If pass1 = pass2 And pass1 <> "" Then
                con.Open()
                Dim daa As OleDb.OleDbDataAdapter
                Dim dss As New DataSet
                daa = New OleDb.OleDbDataAdapter("select * from Login", con)
                Dim cb As New OleDb.OleDbCommandBuilder(daa)
                Dim i As Integer
                Dim di As DataTable = ds.Tables("Login")
                daa.Fill(dss, "Ex_m")
                dss.Tables("Ex_m").Rows(0).Item(2) = pass1
                Try
                    i = daa.Update(dss, "Ex_m")
                    MsgBox("Records Updated= " & i & " , " & dss.Tables("Ex_m").Rows(0).Item(1).ToString() & " , " & dss.Tables("Ex_m").Rows(0).Item(2).ToString())
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
                con.Close()
                con.Open()
                da = New OleDb.OleDbDataAdapter("select * from System", con)
                Dim cb2 As New OleDb.OleDbCommandBuilder(da)
                da.Fill(ds, "Ex_m")
                'ds.Tables("Ex_m").Rows(0).Item(3) = True
                da.Update(ds, "Ex_m")
                con.Close()
            Else
                con.Close()
                MsgBox("Please restart the application and Enter valid Admin Password")
                End
            End If
        End If
        con.Close()
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by adam_k
0

Since you are only changing 1 field for 1 record, wouldn't it be easier and cleaner to just go ahead and update instead of using datasets?

dbprovider = "Provider=Microsoft.ACE.OLEDB.12.0;"
        dbsource = "Data Source=|DataDirectory|\Ex_m.accdb;" & "Persist Security Info=True;" & "Jet OLEDB:Database Password=123456"
        con.ConnectionString = dbprovider & dbsource
        Dim ds As New DataSet
        con.Open()
        sql = "select * from  System"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "Ex_m")
        If ds.Tables("Ex_m").Rows(0).Item(3) = False Then
            Dim pass1, pass2 As String
            con.Close()
            pass1 = InputBox("Please Enter ADMIN Password")
            pass2 = InputBox("Please Re-enter ADMIN Password")
            If pass1 = pass2 And pass1 <> "" Then
                con.Open()
                Dim dc As OleDb.OleDbCommand("update Login set password = '" & pass1 &"' where user_name = 'ADMIN'",con)
'the update might need changes on the fields and criteria
                 dim i as integer
                Try 
                   i = dc.ExecuteNonQuery

                    MsgBox("Records Updated= " & i )
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
                con.Close()
                con.Open() ' change as above
                da = New OleDb.OleDbDataAdapter("select * from System", con)
                Dim cb2 As New OleDb.OleDbCommandBuilder(da)
                da.Fill(ds, "Ex_m")
                'ds.Tables("Ex_m").Rows(0).Item(3) = True  
                da.Update(ds, "Ex_m")
                con.Close()
            Else
                con.Close()
                MsgBox("Please restart the application and Enter valid Admin Password")
                End
            End If
        End If
        con.Close()

Edit: Read here for info on OleDbCommand class: http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand(v=VS.100).aspx

Edited by adam_k: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.