English 中文(简体)
c#/sql-server,试图从两个表格中获取2个dl数据。 数据
原标题:c#/sql-server, trying to get data to two ddl s from two tables...in one sqlDataReder

Well, i am tring to do something nice (nice for me, simple for you guys), i was told i can do it, but i have no idea where to start. I have two DDL s in a page, i need on page_load to popolate both, each one gets data from deferent table with no relaition between them (suppliers/catagories). i know how to do it with two DB connections, that is easy, but i was told that i can do it with one connection. I was not told if it is only the connection that is united or also that SP deal with both tables in one SP (doesn t seem logical to me that i can do it with only one SP...but what do i know..lol) thanks, Erez

最佳回答

I think you could separate your SQL statements by a semicolon.
e.g. SELECT myColumns FROM Suppliers; SELECT otherColumns FROM Categories

您可以定期开放数据读物。

一旦你们阅读了1st resultset的所有数据,你就可以打电话到NextResult<<<>a>,该编码将试图执行下一份声明,并将让你们阅读2nd resultset。

注:我没有这样做。 但这是我从文件中可以做的。

问题回答

您可以在《战略》中提出两个问题:

页: 1

  select * from table1;
  select * from table2;

然后,在C#一侧,你打开数据读物,你可以使用读物。 接下来的恢复方法得出了结果。

while (reader.Read())                                              
{                                                                  
   // process results from first query                             
}                                                                  

reader.NextResult();                                               
while (reader.Read())                                              
{                                                                  
   // process results from second query                            
}                                                                  

不仅我这样做的方式(即使用2个物体数据来源);而且,如果你真的只想使用1个物体,就这样做:

Create one sql statement that contains 2 select statements; and load that into a C# DataSet.
Bind your first ddl to DataSet.Tables[0].
Bind your second ddl to DataSet.Tables[1].

这里有1条连接。

EDIT:如果你真想使用数据

你可能需要2份选委发言,并需要一个额外的领域来区别你们重新插入的DDL。 因此:

SELECT Table1 AS TableName, Name, Value FROM dbo.Table1

意 见

SELECT Table2 AS TableName, Name, Value FROM dbo.Table2

接着,无论用何种方法,你重新将物品装入你的DDL,检查桌子名称,看看看谁添加到哪里。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签