User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 425,895 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,931 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 1170 | Replies: 5 | Solved
Reply
Join Date: Mar 2008
Posts: 9
Reputation: nerden is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nerden nerden is offline Offline
Newbie Poster

VB.NET 2008, datagrid query

  #1  
May 28th, 2008
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2006
Location: Egypt
Posts: 762
Reputation: RamyMahrous is on a distinguished road 
Rep Power: 4
Solved Threads: 59
Featured Poster
RamyMahrous's Avatar
RamyMahrous RamyMahrous is offline Offline
Master Poster

Re: VB.NET 2008, datagrid query

  #2  
May 28th, 2008
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

  1. 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
B.Sc Computer Science, Helwan University
Microsoft Student Partner
Personal blog http://ramymahrous.blogspot.com/
Arabic technical blog http://fci-h-ar.blogspot.com/
English technical blog http://fci-h.blogspot.com/
Reply With Quote  
Join Date: Mar 2008
Posts: 9
Reputation: nerden is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nerden nerden is offline Offline
Newbie Poster

Re: VB.NET 2008, datagrid query

  #3  
May 29th, 2008
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
Reply With Quote  
Join Date: May 2007
Posts: 36
Reputation: cellus205 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
cellus205 cellus205 is offline Offline
Light Poster

Re: VB.NET 2008, datagrid query

  #4  
Jun 5th, 2008
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.
Reply With Quote  
Join Date: Mar 2008
Posts: 9
Reputation: nerden is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nerden nerden is offline Offline
Newbie Poster

Re: VB.NET 2008, datagrid query

  #5  
Jun 24th, 2008
Thank you very much "cellus205", sorry it took so long to reply, wich finishing uni and stuff.

cheers
Reply With Quote  
Join Date: Mar 2008
Posts: 9
Reputation: nerden is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nerden nerden is offline Offline
Newbie Poster

Re: VB.NET 2008, datagrid query

  #6  
Jun 24th, 2008
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)
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb VB.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 7:20 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC