转换的SqlDataSource到数据表和数据视图 [英] Convert SqlDataSource to DataTable and DataView
问题描述
我有如下的的SqlDataSource
,我想将其转换为数据视图
,并从中读取列:
I have the following SqlDataSource
and I want to convert it to DataView
and read a column from it:
SELECT
dbo.Divisions.DivisionShortcut,
COUNT(DISTINCT dbo.UserQuiz.Username) AS [Number of Participants]
FROM
dbo.Divisions
INNER JOIN
dbo.employee ON dbo.Divisions.SapCode = dbo.employee.DivisionCode
INNER JOIN
dbo.UserQuiz ON dbo.employee.Username = dbo.UserQuiz.Username
INNER JOIN
dbo.Quiz ON dbo.UserQuiz.QuizID = dbo.Quiz.QuizID
WHERE
(dbo.Quiz.QuizID = @QuizID)
GROUP BY
dbo.Divisions.DivisionShortcut
本的SqlDataSource
允许用户进入测验的数量,它将检索参与者在测验的总数。我想这个的SqlDataSource
转换为数据表
并从中读取列。
This SqlDataSource
lets the user enter the number of the Quiz, and it will retrieve the total number of participants in that quiz. I want to convert this SqlDataSource
to a DataTable
and read a column from it.
那么怎么办呢?
推荐答案
让我说你有一个的SqlDataSource
命名为SqlDataSource1
Let me say you have an SqlDataSource
named as SqlDataSource1
DataSourceSelectArguments args = new DataSourceSelectArguments();
DataView view = (DataView)SqlDataSource1.Select(args);
DataTable dt = view.ToTable();
现在你可以从这个DT(数据表),例如易于阅读的一列。
Now you can read a column easily from this dt(DataTable) e.g.
int columnNumber = 0;
for(int i=0;i<dt.Rows.Count;i++)
{
MessageBox.Show(dt.Rows[i][columnNumber].ToString());
}
<一个href=\"http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/thread/a0d1bbbc-27b1-41c9-b14f-7c5be2c9e33f#39e551e5-1714-45c6-b732-1125704cfc38#39e551e5-1714-45c6-b732-1125704cfc38\"相对=nofollow>参考
这篇关于转换的SqlDataSource到数据表和数据视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!