Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to show some field of relational database in gridview, tables are :
tbl_User :UserId,UserName,LastName
tbl_Product :UserId,productId, productName , Price
(PrimaryKey :UserId , ForiegnKey :ProductId)

and I wanna to show UserName,LastName,productName,Price in gridview ...

But it doesn't show data content? what's the wrong with that??
Posted
Comments
Michel [mjbohn] 3-Feb-12 13:43pm    
Let me look into my crystal ball...
No, sorry. Can't see what's wrong with your code ;)
Orcun Iyigun 3-Feb-12 13:45pm    
can you show code? maybe the query and the way you bind your gridview helps us to figure out what might be the problem.
EhsanGhanbari 3-Feb-12 15:42pm    
I haven't write any query , I just bind my gridview and the code is like this ,
(I mentioned the names of above for example, my real grid made query is this ):
SELECT [User].UserId, Tender.UserId AS Expr1, Tender.Price, Tender.Name, [User].LastName, [User].UserName
FROM [User] INNER JOIN
Tender ON [User].UserId = Tender.UserId

1 solution

If the gridview isn't showing any results, use the debugger to see if:

  • results are coming from the database
  • the data is correctly binded to the gridview
  • necessary columns exist/are created and so on.


If the problem is in the query, start with a simple one and then introduce more conditions to see if they are eliminating all rows.

Based on your description the initial query to test could be something like:
SQL
select *
from tbl_user u, tbl_product p
where u.UserId = p.UserId
 
Share this answer
 
Comments
EhsanGhanbari 3-Feb-12 15:45pm    
my gridview works correctly in the case of binding from only one table , but whenever I want to query from joined table , it shows blank...
Wendelius 3-Feb-12 16:06pm    
Then it sounds like there are no records in the database that would satisfy the join condition. Did you use the debugger to see if any rows are returned. Also use SSMS (if this is SQL Server) to test your query.

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