c#.net中的数据集 [英] Dataset in c#.net

查看:68
本文介绍了c#.net中的数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...
我正在将ASP.NET与C#一起使用.
我在.aspx页面中有Gridview,我想将gridview绑定到数据集.
Iam通过
将Gridview绑定到数据集 Gridview.datasource = ds;
Gridview.Databind();
我的gridview格式是:
用户结果1结果2结果3
用户1
User2
User3
(对于结果表中的所有结果"和用户表中的用户".)
我正在使用:
string strOutcome =从结果中选择不同的名称作为exp group By Name";
DataSet dsout = new DataSet();
SqlDataAdapter adpout =新的SqlDataAdapter(strOutcome,conn);
adpout.Fill(dsout);
DataSet ds = new DataSet();
DataTable dtble =新的DataTable("tmp");
dtble.Columns.Add(new DataColumn("Users",typeof(string)));

foreach(dsout.Tables [0] .Rows中的DataRow drout)
{
dtble.Columns.Add(new DataColumn(Convert.ToString(drout ["Name"]))));
}

ds.Tables.Add(dtble);

字符串strUser =按用户名从User_Mast组中选择用户名";
DataSet dsUser =新的DataSet();
SqlDataAdapter adpUser =新的SqlDataAdapter(strUser,conn);
adpUser.Fill(dsUser);

foreach(dsUser.Tables [0] .Rows中的DataRow drUser)
{
DataRow drow = ds.Tables [0] .NewRow();
drow ["Users"] = Convert.ToString(drUser ["UserName"]);
ds.Tables [0] .Rows.Add(drow);

}


通过这种方式,我在gridview格式以上.
但是现在我不得不从同时具有用户和结果字段的数据库表查询中提取数据.
我想根据他们的结果来检索特定用户的总数.

Hi...
I am using ASP.NET with C#.
I am having Gridview in .aspx page and i want to bind gridview to dataset.
Iam binding Gridview to dataset through
Gridview.datasource=ds;
Gridview.Databind();
My gridview format is:
Users Outcome1 Outcome2 Outcome3
User1
User2
User3
(for all Outcome from Outcome table and Users from User Table.)
I am using:
string strOutcome = "Select Distinct Name from Outcome as exp group By Name";
DataSet dsout = new DataSet();
SqlDataAdapter adpout = new SqlDataAdapter(strOutcome, conn);
adpout.Fill(dsout);
DataSet ds = new DataSet();
DataTable dtble = new DataTable("tmp");
dtble.Columns.Add(new DataColumn("Users", typeof(string)));

foreach (DataRow drout in dsout.Tables[0].Rows)
{
dtble.Columns.Add(new DataColumn(Convert.ToString(drout["Name"])));
}

ds.Tables.Add(dtble);

string strUser = "Select UserName from User_Mast group by UserName";
DataSet dsUser = new DataSet();
SqlDataAdapter adpUser = new SqlDataAdapter(strUser, conn);
adpUser.Fill(dsUser);

foreach (DataRow drUser in dsUser.Tables[0].Rows)
{
DataRow drow = ds.Tables[0].NewRow();
drow["Users"]=Convert.ToString(drUser["UserName"]);
ds.Tables[0].Rows.Add(drow);

}


By this i am getting above format in gridview.
But now i have to retieve data from database table Enquiry having both fields User and Outcome.
i want to retrieve total count for particular user against their outcome.
how to do that??

推荐答案

为什么您没有以所需的格式取回数据集?当然,对于aspx,这些代码是否不全在您的代码中?

您可以使用SQL中的select count语句检索总计数.
Why on earth are you not getting back a dataset in the format you want ? Surely this code is not all in your code behind for the aspx ?

You retrieve a total count with the select count statement in SQL.


这篇关于c#.net中的数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆