Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't get a Select sql statement to work

Status
Not open for further replies.

Hobeau

MIS
Apr 19, 2004
77
US
Hi, I'm really new at database programming. I've got VB.net and I'm working on a very simple practice program that is linked to a Access Database. I have a database that I set up with just a Primary key called "ID" , a last name and first name column called "LastName" and "FirstName". I'm able to link everything up and I can get the data to fill a datagrid, or a combo box just fine before I write the SQL satement, but after I write the Select SQL statement that is associated with the LastName I try to fill data grids and such and there it won't display any data. The SQL statement is Select FirstName, LastName Where LastName = "lname"

This is the code to fill:
Code:
'This starts the combo box off 
oledbdatabase1.fill(dataset11)
combobox1.SelectedIndex = -1

If combobox1.SelectedIndex <> -1 Then
     dataset11.Clear()         oledbdataadapter1.SelectCommand.Parameters("lname").Value = combobox1.Text
oledbdataadapter1.Fill(dataset11)
End if

The "if" statement is supposed to fill 2 other labels that are bound to the first and last name columns and fill them with the information that is limited by the Select statement. For some reason no data is showing as soon as I input the SQL statement, but when I take the statement out, it stops displaying any data at all. Can anyone help?
 
You need to put a FROM clause in your SQL so the DB knows from which table to get the data:

Select FirstName, LastName FROM <tablename> Where LastName = 'lname'

Put your table's name for <tablename>

Note that lname is now enclosed in single quotes

Also note that this query as it is now written, will only return records where the LastName field's value actually is "lname"

Here's a link to a SQL tutorial you might find helpful:

SQL Tutorial

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top