Searching a dataset

yeshia

New member
Joined
Dec 2, 2005
Messages
1
Programming Experience
Beginner
I am trying to make a program where a user enters a course number, and the program searches the dataset for that course number, then displays the course info (name, time etc..) I am a beginner. How can I take input from the user, and search, line by line, until the correct record is found? Thanks.
 
If you are using SQL, then as Manic said configure your dataAdapter to SELECT {fields} FROM {table} WHERE CourseNumber = @CourseNumber

NB - CourseNumber is assuming you have used that as the ID. Your parameter (@___) must be the same name, i.e. if you used CourseID, then you put CourseID = @CourseID.

On your form, add a text box, for the course number (don't bind to anything) and a load button.

Then in your load button code, before calling dataAdapter.fill, enter the following line obviously with the correct information in place of the bold text:
Me.DataAdapter1.SelectCommand.Parameters("@CourseNumber").Value = textbox1.text

You can then put some error handling code in, so that if the course number doesn't exist a messagebox informs the user.
I.E.

VB.NET:
Private Sub btnLoad_Click(........)Handles btnLoad.click
   
Me.[B]DataAdapter1[/B].SelectCommand.Parameters("[B]@CourseNumber[/B]").Value = [B]textbox1.text[/B]
Me.[B]DataAdapter1[/B].Fill([B]dataSet1.table1[/B])
If me.dataSet1.table1.rows.count = 0 Then
   MessageBox.Show("Course Number: " & textbox1.text & " not found.", "Course Number Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
 
HTH
Luke
 
Back
Top