Question loading data from access database

killhate

Member
Joined
May 8, 2011
Messages
5
Programming Experience
Beginner
hi everyone,this is very urgent,i'm a beginner in visual basic and i need help with one problem..thing is..i have access database connected to application..
i have a table in database called "clanovi" (members) and first column items loaded to combobox their name and surname..now..when i select one of them from combo box i need all their other info loaded into several text boxes..adress,email etc..all of that info is in the same table ..i need some example code too ..thanks in advance..using oledb provider
 
This is very simple. You simply get all the data into a DataTable to begin with and then bind the data to your controls. When you make a selection in the ComboBox, the other controls update automatically, e.g.
myBindingSource.DataSource = myDataTable

myComboBox.DisplayMember = "SomeColumn"
myComboBox.DataSource = myBindingSource

myTextBox.DataBindings.Add("Text", myBindingSource, "SomeOtherColumn")
This code uses a BindingSource so you would obviously have to add one of those to your form.
 
thanks for that but what should i put instead of mybindingsource or how do i add it to my project, as i said i am very new to vb.

EDIT:

i am using this function to connect to any table in database,my friend helped me do it..

Public Sub Connection(ByVal tablica As String)
ds.Clear()
ds.Tables.Clear()
da = New OleDb.OleDbDataAdapter
con = New OleDb.OleDbConnection
dbProvider = "Provider=Microsoft.ACE.OLEDB.12.0;"
dbSource = "Data Source=bazy-tenis.accdb;Persist Security Info=False;"
con.ConnectionString = dbProvider & dbSource
con.Open()
sql = "SELECT * FROM " & tablica
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, imeBB)
con.Close()
akcijaUpdate(imeBB)
End Sub

"ds" is dataset and "da" is dataadapter..can you make that code somehow fit into that..
 
Last edited:
And as I said:
This code uses a BindingSource so you would obviously have to add one of those to your form.
How do you usually add things to a form? You do this the same way.
 
i am obviously doing something wrong.i entered this code



Dim mybindingsource As BindingSource
        Dim mydatatable As DataTable
        mybindingsource.DataSource = myDataTable

        comboClanPretraga.DisplayMember = "imeprezime"
        comboClanPretraga.DataSource = mybindingsource

        textClanMjesto.DataBindings.Add("Text", mybindingsource, "mjesto")


and i get the error Object reference not set to an instance of an object.
 
Last edited:
Object reference not set to an instance of an object
This means you haven't created an object.
Dim mybindingsource As BindingSource
Here you have declared a variable of type BindingSource, but not created an object and assigned to it. Use the New keyword to create a new object, aka "... As New ...".
 
now i get

Cannot bind to the property or column mjesto on the DataSource.
Parameter name: dataMember

:( is anyone willing to take my project and do that for me..
 
1. Read.
2. Do.

You simply get all the data into a DataTable to begin with
Where are you populating the DataTable?
This code uses a BindingSource so you would obviously have to add one of those to your form.
Add it to the form, just like you would a TextBox or a Button.
 
i added bindingsource and still it doesnt work..i just dont know how to make that i'm too stupid for this...that's why i asked for help...i am total noob..
 
Back
Top