Searching for records in a database
I am trying to search for matching records in a database. Example: I search the student number 10000, if it matches a student it brings up information about the student(name, age etc.) If it doesn't match, I tell the user that it has no matches.
EDIT: got some help from professor, not sure what panStudentRecord is for? and why it doesent work as is.
EDIT: Figured it out, he meant for us to use a panel to contain the student info, the pantStudent line was to make it visible
Code:
TblStudentsBindingSource.Filter = "StudentNumber =" & txtStudentNumber.Text
If TblStudentsBindingSource.Count = 1 Then
panStudentRecord.Visible = True
End If
End Sub
Re: Moving through database records
I'm not quite sure what the question is. Is the code you showed actually working? It doesn't seem like it should be, because the first line seems kind of improbable. For example, txtStudentNumber sure looks like it must be a textbox, since you use the .Text property later on. So, that would mean you are checking whether or not a control (not the contents of the control, but the control itself) is Null. Can that EVER be true?
You then appear to be using a strongly typed dataset. That would be unfortunate for a class, since those tend to leave the whole database activity sealed in a black box, but I guess that depends on the nature of the class. However, what is it you are trying to do? That looks like something of a search statement, though you don't do anything if a match is found. The subject line suggests that you then want to navigate around rather than searching, so are you trying to go from one row to the next within a datatable in the dataset?
Re: Moving through database records
1. I'm not sure about the code, I literally copied it here and changed the important variables, hoping it might help, now looking at it and your response I'd say it doesen't.
2. To clarify my question I mean to type in a student number and if it matches a student number in my records to bring up the relevant information for that student(name, age, courses, loans etc.) I'll change the subject line and my OP to reflect that
Re: Moving through database records
i REALLY suggest you do this little begginers tutorial on Databases, it includes all the basic functions of working with databases from VisualStudio. Deleting, Adding, Searching and Navigate the records ! http://www.homeandlearn.co.uk/NET/nets12p1.html
Re: Searching for records in a database
I'd second that suggestion...with one qualification: This appears to be some kind of classwork. If that is the case, then it is likely that there are things you are allowed to do and things that you are not allowed to do. When it comes to databases, there is one big chasm dividing two different approaches to things. That site is likely to show you the guts of the subject, which is what I much prefer, and pretty much all I do. They are talking about datareaders, connections, and commands. However, there is a different approach. Rather than dataadapters, there are also tableadapters. Rather than datasets, there are strongly typed datasets. In the world of dataadapters and strongly typed datasets, I'm not sure that datareaders, and command objects even exist (they do, but they may be totally hidden from you), and even connections are a different animal.
So, if you look at that tutorial and can say "I recognize this stuff and am allowed to use it." then that's a great start. However, in the snippet you showed, which I realize you didn't write (reuse code rather than writing fresh, whenever possible), that was using strongly typed datasets, so it's the other realm. If the class requires you to use tableadapters and strongly typed datasets, then...well, that would be unfortunate, but that would also mean that the tutorial would be much less useful to you.