private void GetCategory3()
{
SqlConnection myConn = new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
SqlDataAdapter da = new SqlDataAdapter("Select top 15 id, toptypes, typesname FROM comtypes WHERE toptypes=0 ORDER BY pn asc; Select toptypes, id, typesname FROM comtypes ORDER BY pn ASC", myConn);
DataSet ds = new DataSet();
try
{
da.Fill(ds);
ds.Tables[0].TableName = "Category1";
ds.Tables[1].TableName = "Category2";
DataColumn Parent = ds.Tables["Category1"].Columns["id"];
DataColumn Child = ds.Tables["Category2"].Columns["toptypes"];
DataRelation tableRelation = new DataRelation("tableRelation", Parent, Child,true);
ds.Relations.Add(tableRelation);
dt1.DataSource = ds.Tables["Category1"];
dt1.DataBind(); }
catch (Exception error)
{
Response.Write(error.ToString());
}
}
现在主表我已经用top15控制显示15条数据,现在我要求只显示每个子表的数据也是15条的时候,不知道如何控制了,希望有高手指导一下
{
SqlConnection myConn = new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
SqlDataAdapter da = new SqlDataAdapter("Select top 15 id, toptypes, typesname FROM comtypes WHERE toptypes=0 ORDER BY pn asc; Select toptypes, id, typesname FROM comtypes ORDER BY pn ASC", myConn);
DataSet ds = new DataSet();
try
{
da.Fill(ds);
ds.Tables[0].TableName = "Category1";
ds.Tables[1].TableName = "Category2";
DataColumn Parent = ds.Tables["Category1"].Columns["id"];
DataColumn Child = ds.Tables["Category2"].Columns["toptypes"];
DataRelation tableRelation = new DataRelation("tableRelation", Parent, Child,true);
ds.Relations.Add(tableRelation);
dt1.DataSource = ds.Tables["Category1"];
dt1.DataBind(); }
catch (Exception error)
{
Response.Write(error.ToString());
}
}
现在主表我已经用top15控制显示15条数据,现在我要求只显示每个子表的数据也是15条的时候,不知道如何控制了,希望有高手指导一下
解决方案 »
- -------------////////关于前台传值问题
- 想做个网站,谁有免费资源提供个模版给我,界面模版就行,后台代码我自己加
- 请问oledbparameter使用的sql语句可否这样写,为什么
- Lucene 范围查询问题。有分都给了
- 帮忙解释一下``急``
- 一个cookies的判断我写出来了,但是我不明白他的意思,请高手给讲讲
- asp.net gzip
- 急,在线等!做网页时遇到的几个问题!!!
- 如何在实现html文件中显示访问者ip地址
- 写一个qq第三方登录
- 可以不可以在 <script language="javascript" type="text/javascript">里面给DropDownList添加项
- 请教大家,能不能实现这样的功能,地址栏显示的域名和实际的页面域名是不一样的!
http://dotnet.aspx.cc/article/54f4c732-aae2-4135-fb1b-7b4b613baa33/read.aspx
http://dotnet.aspx.cc/article/33e3cfc4-7cf1-48f1-a013-45ff9fa06e03/read.aspx
http://dotnet.aspx.cc/article/f73eeaa9-2bdc-47fd-afd2-59f2fa4897f5/read.aspx
我说了用DataRelation实现啊
{
SqlConnection myConn = new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
SqlDataAdapter da = new SqlDataAdapter("Select top 15 id, toptypes, typesname FROM comtypes WHERE toptypes=0 ORDER BY pn asc; Select toptypes, id, typesname FROM comtypes ORDER BY pn ASC", myConn);
DataSet ds = new DataSet();
string sql1 = "Select top 15 id, toptypes, typesname FROM comtypes WHERE toptypes=0 ORDER BY pn asc";
SqlDataAdapter sda1 = new SqlDataAdapter(sql1,myConn);
sda1.Fill(ds, "parent");
string sql2 = "Select top 15 toptypes, id, typesname FROM comtypes ORDER BY pn ASC";
SqlDataAdapter sda2 = new SqlDataAdapter(sql2, myConn);
sda2.Fill(ds, "child"); try
{
//da.Fill(ds);
//ds.Tables[0].TableName = "Category1";
//ds.Tables[1].TableName = "Category2";
//DataColumn Parent = ds.Tables["Category1"].Columns["id"];
//DataColumn Child = ds.Tables["Category2"].Columns["toptypes"];
//DataRelation tableRelation = new DataRelation("tableRelation", Parent, Child,true);
//ds.Relations.Add(tableRelation);
//下面将上面注释掉的关系写到一起 ds.Relations.Add("tableRelation", ds.Tables["parent"].Columns["id"], ds.Tables["child"].Columns["toptypes"]);
dt1.DataSource =ds.Tables["parent"].DefaultView;
dt1.DataBind(); }
catch (Exception error)
{
Response.Write(error.ToString());
}
}