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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get multiple values from one query

Status
Not open for further replies.

johnc83

Technical User
Jan 29, 2008
154
GB
Hi again, sorry for those who have noticed my many recent posts but I so close to completion now! :)

If I have two textboxes (CustomerName), (CustomerContact), is it possible to run ONE query against the tblCustomers which will fill in both of them boxes?

I don't want the textboxes to be bound or anything like that, just stand-alone boxes.

Or do I need to run two separate select queries?

Thanks

John

.NET 2.0, Visual Studio 2005, SQL Server 2005 Express
 
You have a couple diff ways you can do this.

You can create a stored procedure that returns all the data that you are going to need. then in the function that gets this data, set all the textboxes to their values.

You can also creata a DataSource, which requires very little code on your part, but sort of fuzzies the whole working with the database part, and introduces binding.


Your request sounded like you wanted to run one stored procedure, and return 2 select statement results, which is possible.

-Sometimes the answer to your question is the hack that works
 
Hi there, thanks for the reply.

Did you get my original reply? Sure I sent it and you replied to that but seems to have gone missing?

It was basically asking how do I set the textboxes to the results of the query (as in your first suggestion)

Does it make a difference that the 'textbox' will actually be a cell on a datagridview row?

Cheers
John

.NET 2.0, Visual Studio 2005, SQL Server 2005 Express
 
if you are hooking up to a datagrid, you can use a binding source or a data table as the .datasource and it will fill in the datagrid for you.

-Sometimes the answer to your question is the hack that works
 
Hi again, my datagrid already has a bindingsource which saves back to the table.

Datagrid has 4 columns: ProductCode, ProductName, QTY, Price

My idea is to enter the ProductCode which will then populate the ProductName box from tblProducts and the Price from the same table (QTY is always 1).

How do I make a query which says "Get me the productname and put it in column 2 and get me the price and put it in column 3"?

Cheers

John







.NET 2.0, Visual Studio 2005, SQL Server 2005 Express
 
Ahh, i see what you are getting at now.

You will be working with a data grid like you would with Excel.

you will need to trap the cell exit event and ensure that there is valid data in cell 1, then you can call the get values procedure, and then search through the datagrid for the specific row that you need then set the datagrid row item value to what you want.

OTOH

You may want to re-eval your design and consider a mini entry form and use the datagrid for actual items that they want. Have a item# text box and a qty box.
on the text leave event you can get the name and the price.
Then you can just add a row to datagrid in a "add to cart" button.





-Sometimes the answer to your question is the hack that works
 
Hi again, got it working now.

thanks a lot for your help

John

.NET 2.0, Visual Studio 2005, SQL Server 2005 Express
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top