[英]How can I use a single SQL string to create a data-set from multiple tables in C#?
I'm new to C#, and I'm kinda clueless about how to use a single sql-string to retrieve data from multiple tables (3 of them, actually). 我是C#的新手,我对如何使用单个sql字符串从多个表(实际上是3个表)中检索数据一无所知。
basically there are 2 master-files: 基本上有2个主文件:
And 1 transaction-file: 和1个交易文件:
And that's alright. 没关系。 But now i need to run a command that will retrieve data from ALL 3 tables based on a search-parameter entered by the user, and display selected fields in all of them.
但是现在我需要运行一个命令,该命令将根据用户输入的搜索参数从所有3个表中检索数据,并在所有表中显示选定的字段。 in ms access, all i had to do was make a query - here's the generated sql:
在ms access中,我要做的就是查询-这是生成的sql:
SELECT Assignments.Task_No, Assignments.Assignment_No, Assignments.Assignment_Date,
Task_Information.Client_Name, Emp_Information.F_Name, Emp_Information.L_Name
FROM Emp_Information
INNER JOIN (Task_Information
INNER JOIN Assignments ON Task_Information.Task_No = Assignments.Task_No)
ON Emp_Information.Emp_ID = Assignments.Assignee
WHERE (((Assignments.Assignment_Date)="this is just some date the user has to enter..."))
In short, I need to find out how to use the same sql-string in a C# program where the user types the search parameter and clicks a button. 简而言之,我需要找出如何在C#程序中使用相同的sql字符串的方式,在该程序中,用户键入搜索参数并单击一个按钮。 btw, it's got to be done with an oledbdatareader/adapter;
顺便说一句,必须使用oledbdatareader / adapter完成;
Try this query: 试试这个查询:
SELECT Assignments.Task_No, Assignments.Assignment_No, Assignments.Assignment_Date,
Task_Information.Client_Name, Emp_Information.F_Name, Emp_Information.L_Name
FROM Emp_Information
INNER JOIN Task_Information
ON Task_Information.Task_No = Assignments.Task_No
INNER JOIN Assignments
ON Emp_Information.Emp_ID = Assignments.Assignee
WHERE (((Assignments.Assignment_Date) like "%this is just some date the user has to enter...%"))
if you would work with an SQL Server you could use the SqlCommand
. 如果要使用SQL Server,则可以使用
SqlCommand
。 With this you would replace your string "this is..."
with a parameter placeholder @date
, which could then be set like shown on MSDN . 这样,您将用参数占位符
@date
替换字符串"this is..."
,然后可以像在MSDN上所示进行设置。
The main problem here would be the usage of the OleDbDataReader
and if it supports this kind of query. 这里的主要问题是
OleDbDataReader
的使用以及它是否支持这种查询。 But after reading the MSDN for OleDbCommand.Parameters
it should work. 但是在阅读了MSDN的
OleDbCommand.Parameters
它应该可以工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.