Pulling info from an access db.

enigmakthx

New member
Joined
Sep 12, 2010
Messages
1
Programming Experience
Beginner
Hey guys, new here, thought I'd see if I could get some help because I'm in a bit of a bind.

I'm making a program that signs students in and out of school using their student ID number for an assignment that is due tomorrow.

I have a database called students with Rows for studentID, First name, and Last name (in that order, called studentID, First, Last respectively) and I have a text box where the ID number is entered. After I hit the OK button there's two things I need to do:

Firstly I need to check whether the studentID entered in the box exists in the database. If it doesn't exist I'm just displaying a MsgBox to tell the user the ID isn't found. If it does exist, I need to move on to the second thing.

The second thing I need to do is when the studentID is found, get the information in the adjacent First and Last columns on that row and store them in variables.

I am using Visual Basic 2010 Express and the database is an Access 2007 .accdb file.

Thanks a million in advance if you can help me out.
 
You don;t really need to separate it into two actions like that. You should simply execute a query to get the data, and it will either return a record or it won't. If it doesn't then you display the message and if it does then you use the data. I'd suggest creating an appropriate OleDbCommand and calling ExecuteReader to get an OleDbDataReader. It's HasRows property will tell you whether the ID exists or not and, if it does, you can call Read and then get the data.

You might like to check out the ADO.NET examples here:

Retrieving and Saving Data in Databases

Make sure you READ all the information and don't just copy and paste the code. It won't work as is but will give you all you need to make it work.
 
Back
Top