English 中文(简体)
送上表的服务器成果集
原标题:Assign names to tables in an SQL Server result set

我正在撰写一份储存程序,执行几个连续的<代码>SlectT。 当我通过ADO执行这一程序时。 NET,我的意图是最后添加一个<代码>DataSet,其中载有几个<代码>DataTable物体。 这符合预期。

目前,我依赖<代码>DataSet中的表格顺序,以便与存储程序中的<代码>SlectT的顺序相匹配,但这一顺序确实没有任何意义。 最终必须保持程序的人不必知道预期结果顺序,而保留申请的人也不应该知道程序中的陈述顺序。

我想知道的是,能否在所储存的程序本身内将每一条码的说明的编号上调,然后通过ADO。 NET( seamless密无缝),以便我能够以自己的姓名而不是按其顺序查阅每个桌子?

e.g.

// populate DataSet with results from stored proc
DataSet ds = new DataSet();
dataAdapter.Fill(ds);

// now access one of the resulting DataTable via name
return ds.Tables["NamedResultFromTheProc"];

因此,是否有办法实现这一目标? 或者,我是否必须依靠<代码>SlectT的次序,并且总是按其指数查阅所希望的表格?

最佳回答

我没有尝试这样做,但你不能改变所储存的原样结构,以便你在每次数据盘问之前有回问地回到桌子的名字?

i.e.

select  TableName ;
select * from Table where 1 = 1;

然后通过创建表格和在表格中添加数据集,以人工方式建立数据集?

问题回答

您询问的表格将贴上“表”、“表1”、“表2”等名称。

在填写你的数据表之前,你可以在数据表上添加表格,以将其打上你的表格:

myAdapter.TableMappings.Add("Table", "MyTable1");
myAdapter.TableMappings.Add("Table1", "MyTable2");
myAdapter.TableMappings.Add("Table2", "MyTable3");

不幸的是,我认为这是不可能的! 我有一个类似的机构,从储存程序获得数据表,在我找回并采用索引。

这不是最佳解决办法,但你可以把问询的第一栏改为:

    Select  Customer , CustomerID, CustomerName, CustomerAddress
    From Customer
    Where CustomerID = @CustomerID;
    
    Select  Orders , OrderID, OrderPrice, OrderDate
    From Order O
    Join Customer C on C.CustomerID = O.CustomerID
    Where C.CustomerID = @CustomerID;
    
    Select  OrderItems , ItemID, ItemDescription, ItemPrice
    From OrderItems I
    Join Order O on O.OrderID = I.OrderID
    Join Customer C on C.CustomerID = O.CustomerID
    Where C.CustomerID = @CustomerID;

It is not possible, but its SQL "fault", not the fault of DataAdapter/Set, because result set does not carry the name of the table queried (nor is that discernibly possible if you use inner join) nor does the table adapter have a query from which to pick the name. One method you can use is to first return a list of tables as Query#0 in the procedure, e.g.

select  MyTable;MySecondTable;ThirdOrSo  as tables

随后,所有其他询问,即索引0表和这个领域,将数据集中的其他表格分开/改用。 维护者仍需要知道这一机制,但至少让他有重组的自由。

我也想到这一点,我认为唯一的解决办法是,在程序内设立临时表格,并将结果集中到那里(在你看来,表格的名称)。

然而,我并没有尝试过这一点,因为我不认为这样做的正确方式是必须两次获得结果(按温桌排列,询问时间表)。

如果你能够把你以同样的方式确定的结果改名为“Custom Column”。





相关问题
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. ...

热门标签