是否可以选择2个表并在一个gridview中查看? [英] Is it possible to select 2 tables and view in one gridview?

查看:51
本文介绍了是否可以选择2个表并在一个gridview中查看?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string strQuery =SELECT * FROM Order_Transaction,Order_Purchased WHERE Date_Purchased> ='+ startdate +'AND Date_Purchased< ='+ enddate +';



这可能吗?





其他帮助:建议我可以在库存系统中使用的一些报告技巧。 :)



感谢您的帮助。 :)

string strQuery = "SELECT * FROM Order_Transaction, Order_Purchased WHERE Date_Purchased >='" + startdate + "' AND Date_Purchased <='" + enddate + "'";

Is this possible?


Other help: Suggest some reporting technique that I can use in my Inventory System. :)

Thank you for your help. :)

推荐答案

它有点可能!



假设你的两个订单表都包含一列叫'Order_number'



it is sort of possible!

Assuming your two order tables both contain a column called 'Order_number'

select * 
from Order_Transaction AS OT
  join Order_Purchased as OP 
    ON OT.Order_number = OP.Order_number
WHERE
OT.datePurchased >= @startDate AND OT.datePurchased <= @endDate







使用参数(@startDate和@endDate而不是连接字符串,因为进行字符串连接可能会导致问题(想象一下如果有人输入; drop table Order_Transa 作为其中一个日期?



你没有使用来使用连接语法 - 你可以做到






Use parameters (the @startDate and @endDate rather than concatenating strings, as doing string concatenation can lead to problems (imagine if someone typed "; drop table Order_Transaction" as one of the dates?)

You don't have to use the join syntax - you could do

select *
from Order_Transaction AS OT,
  Order_Purchased as OP
    WHERE OT.Order_number = OP.Order_number





这同样有效,但是往往使用不太广泛



which is equally as valid, but tends to be less widely used


这篇关于是否可以选择2个表并在一个gridview中查看?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆