Click here to Skip to main content
15,910,358 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have to use the select sql query to show the records in grid.

i have to show the productid,productname, productprice, quntity

i want to use to customerid in where clause but customerid is also in the database table. i don't want to show it in my gridview control.. and use as where customerid= label1.text.

but i want to fetch it from the database without showing it to grid.

how can i do it?
Posted

Very Simple if customerid exists within the same table.
SQL
Select productid,productname, productprice, quntity from TableName
Where TableName.customerid=123 

If you need to join
http://msdn.microsoft.com/en-us/library/aa213234%28v=sql.80%29.aspx[^]
 
Share this answer
 
Comments
codegeekalpha 13-Sep-11 18:15pm    
if the customerid is in another table.. than what i have to do ??
Monjurul Habib 14-Sep-11 3:54am    
then you need to follow the above link for joining.
Hi,

What Exactly do you mean?
what I guess you need something like :

Select Productid,productname,productprice, quntity from tablename where customerid=@value

by running the above query, you wont get customerid in your results.

Notice: using customerid=label1.text is extremely dangerous. I recomend to use parameterized query.
 
Share this answer
 
Comments
codegeekalpha 13-Sep-11 18:16pm    
yeh i want to get as u told.. but i want the @value to come from the database..
aidin Tajadod 13-Sep-11 18:26pm    
To do so you need to have some relation field. you need to some how relate your tables together. Then you can have a join or using sub queries.
for ex: Select Productid,productname,productprice from Table1
inner join Table2 on Table1.PrimaryID=Table2.ForeignID
Where Table2.CustomerID=@value . you can also look at this
http://www.deeptraining.com/litwin/dbdesign/FundamentalsOfRelationalDatabaseDesign.aspx

It seems useful.
codegeekalpha 13-Sep-11 18:35pm    
i know how to joins the table.. u are not exactly understanding the question.

cutomerid=@value..
that @value is the value i want to directly get it from the database. it is not in any asp.net control i mean in textbox e.t.c. i want it fromm database
aidin Tajadod 13-Sep-11 19:22pm    
Ok Sorry, you can say:

select ... From Table1 where CustomerID in (Select CustomerID from Table2)

Hope this can help you.

Please let me know whether I got your question or not.
codegeekalpha 14-Sep-11 16:28pm    
yeh it helps me.. my five

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