Hi,

I’m writing a programme in VB.NET 2008 which uses an access database; I am trying to create a query which uses the value from a textbox say txtStudentNo, to query a DataGridView say grdInfo to only show the student with the entered student number.

The problem I am having is that I can make a query and make it run correctly if the student number is applied in the actual query using the QueryBuilder, however I can not work out how to make said query look at a textbox. Everything I have found so far has been for VB.net 05 and 03, these have all said I need to use something like =@StudentNo but this will not work, Hopefully I’m just missing something simple. Thanks for your time.

Say you've button, when user presses on it fills the grid with the data filtered with your critria, OK?

So, on you button click event handler write this code

this.table1TableAdapter.FillBy(this.myDataSet.myTable, new System.Nullable<int>(((int)(System.Convert.ChangeType(textbox1.Text, typeof(int))))));

N.P: My critria was integer value
sorry but I don't know VB.NET code :)

Even with a little modification im not sure that will work, this query has got to have an eliment in the QueryBuilder which the program can pass arguments to. thank you anyhoo

Right, you should use the =@studentno for your query, so it will be something like

SELECT StudentName FROM StudentTable
WHERE StudentNo = @StudentNo

Where StudentNo is the name of the student number column in your access database , then when you need to call the query it will be

StudentName.Text = StudTableAdapter.StudName(txtStudentNo.text)

Where StudName is the name of your query. Im still pretty new to VB too, but I just did something similar.

Thank you very much "cellus205", sorry it took so long to reply, wich finishing uni and stuff.

cheers

RIGHT, incase anyone ever finds this thread again, microsoft had hidden the bit i was looking for in the depths of hell.
Step one
go to the DataSetDesigner
right click your DataTable
fill stuff out as you would making a normal query using a @xxxxxx as a variable where the x's are the name of the column your want to query (Where StudentNo =@StudentNo) was my line

finish the query ignore the warning about errors on '@'
click on "fillBy,GetDataByxxxxxxx" then go to the proporties pane and under parameters
add a parameter for each of the variables you added in the query

<to filter a DataGridView>
then in your forms code
grdEpLst.DataSource = DataTable1TableAdapter1.GetDataByStudent(txtSearchFilter.text)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.