TechArena Community

TechArena Community (http://forums.techarena.in/)
-   Software Development (http://forums.techarena.in/software-development/)
-   -   sql to work in text box (http://forums.techarena.in/software-development/1213031.htm)

Daren 13-07-2009 03:53 AM

sql to work in text box
 
OK this is taking place in VB.net 2008. I have created datagrids and a search text box where a user will enter a specific type of book for example if they enter business in the text box it will search the database and display all business books in the grid. I dont know how to get my SQL to work in that fashion in accordance with the text box.
here is my SQL that i have

ALTER PROCEDURE dbo.ParameterBookSalesByType


as


SELECT SUM(ytd_sales) AS [YTD_Sales], (SUM(ytd_sales) / COUNT(type)) AS [Average_Sales], type AS [Type], COUNT(type) AS [Books Sold]
FROM titles
WHERE type = type
GROUP BY type

now how do i get it to read from the text box and select the various books to display back to the grid.

thanx

Expertz 13-07-2009 04:40 PM

Re: sql to work in text box
 
Try:
"SELECT * FROM (your table) WHERE (your field) = """ & textbox.text & """"

Hope this helps.

$tatic 13-07-2009 04:50 PM

Re: sql to work in text box
 
That's pretty simple. First except the value from the user. For instance, if a user types "business" (as you said). Now fire a query specifying all the fields that should be displayed in "SELECT" clause. Now the table in "FROM" clause. Bow match the value in the text box with the entries in the table in the "WHERE" clause. Optionally you can sort your result using "ORDER BY" clause.

e.g.

Code:

SELECT * FROM books_collection WHERE books_type = "business";


All times are GMT +5.5. The time now is 11:16 AM.