Click here to Skip to main content
15,997,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I'm a bit new to vb.net.

I have successfully developed a simple navigation, having buttons like first, last, previous and next with "SELECT * FROM CUSTOMERS" with bound controls.

My problem begins with following:
When use "SELECT * FROM CUSTOMERS WHERE (CUSTOMERID=?)" and pass the parameters to command it runs successfully but it shows that my table has only one record instead of 91 records, and while only 1 record is selected I can not move to next or previous record.

I know that this makes sense with sql command, only one record in selected and data is bound with "SELECT * FROM CUSTOMERS", but I have to use sql command with WHERE CLAUSE.
I cant bound 2 datasets.

Is there any way that I can use sql statement with where clause and still manage to access all the records in navigation?

The reason of using WHERE clause is that I'm also searching through CUSTOMERID with textbox and passing the parameters in to select command.

I'm using BOUND CONTROLS.

Is this possible with bound controls or I have to use UNBOUND CONTROLS to achieve this task and what would be the code for it?
Posted
Updated 27-Mar-11 5:56am
v2
Comments
Dalek Dave 27-Mar-11 11:57am    
Edited for Grammar, Syntax and Readability.

You cannot do that. If you still want to show all customers in the grid, you have to return all customers from SQL. You cannot use the WHERE clause for that.

Now, if you want to make sure the record that the user is searching for is visible, then you're going to have to find that record and use one of several methods for getting the DGV to scroll to make that record visible. Read this[^].
 
Share this answer
 
No.

When you use
SQL
SELECT * FROM Customers WHERE (CustomerId=value)
It only returns the records which have a "CustomerId" which is the same as "value". Normally, only one customer will have this value (or you wouldn't know which customer was which), so it returns a single record only.

It's a bit like bank accounts:
SQL
SELECT * FROM Accounts
Will return every account in the bank,
SQL
SELECT * FROM Accounts WHERE (AccountNumber=MyAccountNumber)
Will only return my details.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900