asking about vb programming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Manishgusain
    New Member
    • Jan 2008
    • 1

    asking about vb programming

    hi sir i am the fresher in programming in vb so i want to know that how to connect the database ms access in vb kindly inform me ?
  • daniel aristidou
    Contributor
    • Aug 2007
    • 494

    #2
    Originally posted by Manishgusain
    how to connect the database ms access in vb kindly inform me ?
    Ok....This greatly depends on which version of vb you are using.....
    If you could please post which version of vb you are using....we can give you a more specific answer..

    Comment

    • jamesd0142
      Contributor
      • Sep 2007
      • 471

      #3
      This works for vb2005, and i belive vb.net also.

      add this above you class declaration:
      [code=vbnet]
      Imports System.Data.Ole Db
      [/code]

      THis code allows you to update tables and records etc:
      Just change commandtext and source etc:
      [code=vbnet]
      Dim StrConn As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=c:\Users \Users.mdb"
      Dim oConn As New System.Data.Ole Db.OleDbConnect ion(StrConn)
      Dim con As New System.Data.Ole Db.OleDbCommand
      con.Connection = oConn
      con.CommandType = CommandType.Tex t
      con.CommandText = "insert into tblusers (FirstName,Last Name,Login,[Password], Passwordchanged ) values (" & "'" & txtFirstName.Te xt & "'," & "'" & txtLastName.Tex t & "'," & "'" & txtLogin.Text & "'," & "'" & txtPassword.Tex t & "'," & "'" & strdate & "')"
      'add("insert into tblusers (FirstName,Last Name,Login,[Password], Passwordchanged ) values (" & "'" & "c" & "'," & "'" & "c" & "'," & "'" & "c" & "'," & "'" & "c" & "'," & "'" & strdate & "')")
      '"Update TBLUsers set [login] = " & "'" & "NEW" & "'" & " where [FirstName] = " & "'" & "ab" & "'"
      oConn.Open()
      con.ExecuteNonQ uery()
      oConn.Close()
      [/code]

      This allows you to query the table
      [code=vbnet]
      Dim StrConn As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=c:\Users \Users.mdb"
      Dim oConn As New System.Data.Ole Db.OleDbConnect ion(StrConn)
      Dim da As System.Data.Ole Db.OleDbDataAda pter
      Dim oDS As New System.Data.Dat aSet
      Dim strSQL As String = "Select * From tblUsers"
      da = New OleDbDataAdapte r(strSQL, oConn)
      da.Fill(oDS, "Table1")
      DGV1.DataSource = oDS.Tables("Tab le1").DefaultVi ew
      DGV1.Refresh()
      da = Nothing
      oDS = Nothing
      oConn = Nothing
      [/code]

      Cheers James

      Comment

      Working...