Querying a table in an ms access database

supersal666

Member
Joined
Aug 29, 2007
Messages
10
Location
Manchester, UK
Programming Experience
3-5
Hi everyone, Basically I have a vb.net form with a combobox, 2 textboxes a button and a ListBox.

I have an access database with sales details on it

i need to grab the details of the combobox and textboxes and use them to do a search on the database table then displaying the results into a listbox.

Has anyone got any sample code to point me in the right direction as I'm really struggling with this

any help would be appreciated

Thanks
 
1. what result are u trying to show? 1 single value or a datarow, if its a datarow, use datagridview instead

2. do a query with parameters.. with your table adapter, set ur querys in ur dataset designer

the query shld be something like this

VB.NET:
SELECT     column(if its a single value) or * (if its a datarow)
FROM       DataTable
WHERE     (ColumnNameParameter1 = ?) AND (ColumnNameParameter2 = ?) and (ColumnNameParameter3 = ?)

After which using this query in ur button, call the
VB.NET:
tableAdapter.QueryName(Me.dataset.dataTable, _ 
New System.Nullable(Of Integer)(CType(textbox1.Text.Trim, Integer)), _ 
New System.Nullable(Of Integer)(CType(combobox1.selecteditem)), _ 
New System.Nullable(Of Integer)(CType(combobox2.selecteditem)))

Then placed the returned value, in ur list box if its a single value or datarow in ur datagrid view, i remove that part in my codes bcos i do not know what u are returning..


Note: i use integer in this case, for example only, if ur parameter is a string please replace the datatype to String and the same for other data type

I assumed u use datasets, tableadapter, and binding source as u are using VS 2005 if u are not, pls refer to

http://msdn2.microsoft.com/en-us/library/fxsa23t6(vs.80).aspx and read through it
 
Last edited:
Hi everyone, Basically I have a vb.net form with a combobox, 2 textboxes a button and a ListBox.

I have an access database with sales details on it

i need to grab the details of the combobox and textboxes and use them to do a search on the database table then displaying the results into a listbox.

Has anyone got any sample code to point me in the right direction as I'm really struggling with this

any help would be appreciated

Thanks


For an in depth turoial, you should read the DW2 link in my signature. First, follow the Creating A Simple Data APp section - it teaches how to connect to a database and retrieve records. It also shows how to show related data and how to save info to the db, all in a very good starter. THen read the "Creating a Form To Search Data" section. This will fill in the gaps in your knowledge and lead you capable of doing all that you require. Good luck!
 
Back
Top