Hi! I am having a problem with the project I am working on. The project will have more than one query; however, I cannot get the simple one to work yet. I have a form with two text boxes and a button. I also have an Access database that I want to be able to connect and query to.

The database will have fields such as student name, address, test1 and test2. I want the form to allow a user to put in scores for test1 and test2 in TextBox1 and TextBox2, then query the database to say:

If the value in TextBox1 >= the scores in test1 OR
the value in TextBox2 >= the scores in test2 THEN
display the student name, address, test1 and test2 data on another form.

I know how to do lay out the form, write the query and design the 2nd form for the output. What I am having trouble with is telling VB.Net to take the value of TextBox1 and look it up in test1 (in the database). I have a connection string to the database, I just can't find how to code the textbox to look at the database.

The database is very simple. One table with several columns. Each row of data is independent.

Anyone have any ideas? Thank you for any help you can give.

Space doesn't allow me to do it all here, but I can tell you what to look up in your VB reference.

To select anything from a database, you need to define a CONNECTION; then define a string containing a valid SQL SELECT command. (In this case you should read up on parameter queries, to select rows based on a test, like "... text1Grade <= " (your textbox1.text). Next define a dataadapter (ds) with this connection and select command.
Finally define a dataset (ds).

now you can write code n = da.fill(ds, "MyResult"). "MyResult" is the name you might give to a local table of the rows your requet has retrieved, while n is the number of rows retrieved. (I rurge you to code this inside a try/catch)
dim n as integer = ds.fill(ds,"HiGrades")
if n < 1 then
messagebox.show("No Hi Grades Retrieved.")
end if
catch ex as system.exception
messagebox.show(ex.message, "Retrieval Error")
end try
At this point, your result row(s) are in the table "HiGrades" in the dataset ds. You ay browse them with ...

for each r as datarow in ds.tables("HiGrades").rows
messagebox.show(r.item("Student Name"))

I hope this helps.


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.