By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,590 Members | 663 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,590 IT Pros & Developers. It's quick & easy.

asking about vb programming

P: 1
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 ?
Jan 31 '08 #1
Share this Question
Share on Google+
2 Replies


daniel aristidou
100+
P: 491
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..
Jan 31 '08 #2

jamesd0142
100+
P: 469
This works for vb2005, and i belive vb.net also.

add this above you class declaration:
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.OleDb
  2.  
THis code allows you to update tables and records etc:
Just change commandtext and source etc:
Expand|Select|Wrap|Line Numbers
  1. Dim StrConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Users\Users.mdb"
  2.             Dim oConn As New System.Data.OleDb.OleDbConnection(StrConn)
  3.             Dim con As New System.Data.OleDb.OleDbCommand
  4.             con.Connection = oConn
  5.             con.CommandType = CommandType.Text
  6.             con.CommandText = "insert into tblusers (FirstName,LastName,Login,[Password], Passwordchanged) values (" & "'" & txtFirstName.Text & "'," & "'" & txtLastName.Text & "'," & "'" & txtLogin.Text & "'," & "'" & txtPassword.Text & "'," & "'" & strdate & "')"
  7.             'add("insert into tblusers (FirstName,LastName,Login,[Password], Passwordchanged) values (" & "'" & "c" & "'," & "'" & "c" & "'," & "'" & "c" & "'," & "'" & "c" & "'," & "'" & strdate & "')")
  8.             '"Update TBLUsers set [login] = " & "'" & "NEW" & "'" & " where [FirstName] = " & "'" & "ab" & "'"
  9.             oConn.Open()
  10.             con.ExecuteNonQuery()
  11.             oConn.Close()
  12.  
This allows you to query the table
Expand|Select|Wrap|Line Numbers
  1. Dim StrConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Users\Users.mdb"
  2.             Dim oConn As New System.Data.OleDb.OleDbConnection(StrConn)
  3.             Dim da As System.Data.OleDb.OleDbDataAdapter
  4.             Dim oDS As New System.Data.DataSet
  5.             Dim strSQL As String = "Select * From tblUsers"
  6.             da = New OleDbDataAdapter(strSQL, oConn)
  7.             da.Fill(oDS, "Table1")
  8.             DGV1.DataSource = oDS.Tables("Table1").DefaultView
  9.             DGV1.Refresh()
  10.             da = Nothing
  11.             oDS = Nothing
  12.             oConn = Nothing
  13.  
Cheers James
Jan 31 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.