如何使用vb在asp.net中应用连接查询 [英] How to apply a join query in asp.net using vb
问题描述
我有两个表,即父表和子表,例如
带有字段的类别表 - > catid,category_name
&另一个表是项目 - > itemid,catid,itemname,details,price。
我需要做什么我在项目页面绑定gridview,我需要显示一些细节,例如categoryname, itemname,details&price。
那么我需要的是如何查询,以便通过项目表中存储的catid从类别表中获取类别名称。
桌子就像是
类别
Catid category_name
1鼠标
2键盘
3手机
项目
itemid catid itemname详细价格
1 1 logitech mouse 500
2 3 mobile mobile 5000
当在项目页面的gridview中我想要类别名称而不是那个catid。
请帮忙。
I am having two tables i.e a parent table & a child table such as
Category table with fields -> catid,category_name
& The other table is item -> itemid,catid,itemname,details,price.
What I need to do i bind a gridview on the items page where I need to display few details such as categoryname,itemname,details & price.
So what help I need is how to query, so that I get the category name from the category table through the catid stored in item table.
Tables is like
Category
Catid category_name
1 mouse
2 keyboard
3 mobile
Item
itemid catid itemname details price
1 1 logitech mouse 500
2 3 mobile mobile 5000
when in the gridview of the items page I want category name instead of that catid.
Please help.
推荐答案
如果你想要尝试这样的内部连接显示表中的所有数据。
Try something like this for inner join if you want to show all the data from both the table.
SELECT table1.*,table2.* From table1 inner join table2 on table1.Column = table2.column where table1.column = '1'
尝试:
Try:
SELECT it.itemId, it.catid, it.itemName, ct.Category_name, it.Price
FROM ItemTable it
JOIN CetegoryTable ct
ON it.Catid=ct.catid
你好,
以下是获取完整结果的SQL查询你想要:
Hello,
Following are the SQL query for getting complete result as you want:
SELECT C.Catid, C.category_name, I.itemid, I.itemname, I.details, I.price FROM Category C INNER JOIN Item I ON C.Catid == I.Catid
谢谢,
Thanks,
这篇关于如何使用vb在asp.net中应用连接查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!