使用。net返回SQL过程中的多个列。

时间:2022-08-30 10:05:30

I am using this vb.net code file to call a procedure to get dates (among other things). When I execute this procedure in SQL 2005 Server Management Studio, I get about 10 columns. However when I execute this code, the dataset seems to only have one index value, maybe I am misunderstanding something. When I change this

我正在使用这个vb.net代码文件调用一个过程来获取日期(以及其他东西)。当我在SQL 2005 Server Management Studio中执行这个过程时,我得到了大约10列。然而,当我执行这段代码时,数据集似乎只有一个索引值,也许我误解了什么。当我改变这一切

ds.Tables(0).Rows.Count.ToString

to

ds.Tables(1).Rows.Count.ToString  <---changing the index value to 1 
(or higher)

I get no information. So my question is;

我没有得到信息。所以我的问题是;

Does the DataSet contain the other columns, only not indexed like an array? What I want to do is choose which of the columns to filter out and turn the rest into JSON formatted strings. Any suggestions on how to accomplish that would be greatly appreciated as well

数据集是否包含其他列,只是不像数组那样被索引?我要做的是选择要过滤掉的列中的哪一个,然后将其余的转换成JSON格式的字符串。关于如何实现这一目标的任何建议也将受到极大的赞赏

4 个解决方案

#1


2  

You're talking about "columns" of data, but your code snippet is dealing with Tables of data (resultsets).

您正在谈论的是数据的“列”,但是您的代码片段处理的是数据表(resultsets)。

i.e. if your sproc does something like this:

例如,如果您的sproc做以下事情:

SELECT Column1, Column2, Column3
FROM YourTable
WHERE ID = 123

then you'll have 1 DataTable in your dataset as 1 resultset is returned: ds.Tables(0). This will contain 3 columns: ds.Tables(0).Columns(n) where n is 0 to 2.

然后在数据集中有一个DataTable作为一个resultset返回:ds.Tables(0)。这将包含3列:ds.Tables(0). columns (n),其中n为0到2。

#2


1  

When you do ds.Tables(i).Rows.Count, you're going through the rows that were returned. What exactly are you trying to do?

当你ds.Tables .Rows(我)。伯爵,您正在检查返回的行。你到底想做什么?

#3


1  

For the latter part of your question, JSON, have a look at

对于问题的后一部分,JSON,我们来看看

Microsoft JavascriptSerializer

微软JavascriptSerializer

Its then simply a case of Serialize(ds.Tables(0)) to get yourself a JSON representation

然后,只需使用Serialize(ds.Tables(0))来获得JSON表示

#4


1  

edit

编辑

You can also try this:

你也可以试试这个:

 ds.Tables(0).Rows(0).Items.Count.ToString

and

 ds.Tables(0).Rows(0).Items(0).ToString

prior

之前

You are checking the rows not the columns. What does

您检查的是行,而不是列。什么

 ds.Tables(0).Columns.Count.ToString

return?

回报呢?

#1


2  

You're talking about "columns" of data, but your code snippet is dealing with Tables of data (resultsets).

您正在谈论的是数据的“列”,但是您的代码片段处理的是数据表(resultsets)。

i.e. if your sproc does something like this:

例如,如果您的sproc做以下事情:

SELECT Column1, Column2, Column3
FROM YourTable
WHERE ID = 123

then you'll have 1 DataTable in your dataset as 1 resultset is returned: ds.Tables(0). This will contain 3 columns: ds.Tables(0).Columns(n) where n is 0 to 2.

然后在数据集中有一个DataTable作为一个resultset返回:ds.Tables(0)。这将包含3列:ds.Tables(0). columns (n),其中n为0到2。

#2


1  

When you do ds.Tables(i).Rows.Count, you're going through the rows that were returned. What exactly are you trying to do?

当你ds.Tables .Rows(我)。伯爵,您正在检查返回的行。你到底想做什么?

#3


1  

For the latter part of your question, JSON, have a look at

对于问题的后一部分,JSON,我们来看看

Microsoft JavascriptSerializer

微软JavascriptSerializer

Its then simply a case of Serialize(ds.Tables(0)) to get yourself a JSON representation

然后,只需使用Serialize(ds.Tables(0))来获得JSON表示

#4


1  

edit

编辑

You can also try this:

你也可以试试这个:

 ds.Tables(0).Rows(0).Items.Count.ToString

and

 ds.Tables(0).Rows(0).Items(0).ToString

prior

之前

You are checking the rows not the columns. What does

您检查的是行,而不是列。什么

 ds.Tables(0).Columns.Count.ToString

return?

回报呢?