i created a simple form in vb which has id and name as the fields and i want to link to my table in access,please help me with the code.TIA
linking vb to access databases
Collapse
X
-
There will probably be much better answers than this but this is something I used for a project I was trying so might help you to get started at least :)
it links to c:\db1.mbd and pulls user names from a table called users with 2 columns, with the user name in the second column
Code:Imports System.Data Public Class Form1 Dim con As New OleDb.OleDbConnection Dim n as integer Dim ds As New DataSet Dim tableselect As New Data.DataTable Dim da As OleDb.OleDbDataAdapter Dim sql As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\db1.mdb" con.Open() sql = "SELECT * FROM Users" da = New OleDb.OleDbDataAdapter(sql, con) da.Fill(ds, "Users") tableselect = ds.Tables("Users") Dim comb(tableselect.Rows.Count) As String For n = 0 To tableselect.Rows.Count - 1 comb(n) = New String(ds.Tables("Users").Rows(n).Item(1)) Next n For n = 0 To tableselect.Rows.Count - 1 ComboBox1.Items.Add(comb(n)) Next con.Close() End Sub End Class -
Attempt to achieve it by yourself. Paste some of your codes here that you may find difficult. Please be specific, what version of vb are you using, the backend, etc, and please observe posting guidelines.
Rey SeanComment
Comment