积极答复者
求多个表表总数

问题
答案
-
嗯,没有针对字段,是求每一个表的总的记录数字,最后得到的是这几个表的总的记录数字
给你提示:1)首先把某个数据库中全部的数据表读取出来
2)然后逐一查询多少记录即可。
比如:
List<string> tbnames = new List<string>();
using (SqlConnection con = new SqlConnection("你的连接字符串"))
{
SqlCommand cmd = new SqlCommand("select name from sysobjects where xtype='U ' and name<>'sysdiagrams' order by [name]",con);
con.Open();
SqlDataReader sr = cmd.ExecuteReader();
while(sr.Read())
{
tbnames.Add(sr["name"].ToString());
}
con.Close();
}
然后把全部的数据表逐一统计数据即可。
using (SqlConnection con = new SqlConnection("你的连接字符串"))
{
int totalCount = 0;
con.Open();
foreach(string s in tbnames)
{
SqlCommand cmd = new SqlCommand("select count(*) from "+ s,con);
totalCount +=(int)cmd.ExecuteScalar();
}
con.Close();
}
totalCount就是你要的表总数了。
如果你有其它意见或私下交流,请直接发送maledong_work@foxmail.com;或者
If you do not have QQ, please open the page and download it and click the image to talk or leave message for me.
下载MSDN桌面工具(Vista,Win7)
下载Technet桌面小工具(Vista,Win7)
慈善点击,点击此处- 已标记为答案 梁敬超 2011年10月11日 6:25
全部回复
-
我想取每个表里的总数,然后获得这18个表的总数总和
如果你有其它意见或私下交流,请直接发送maledong_work@foxmail.com;或者
If you do not have QQ, please open the page and download it and click the image to talk or leave message for me.
下载MSDN桌面工具(Vista,Win7)
下载Technet桌面小工具(Vista,Win7)
慈善点击,点击此处 -
就是先统计每个表中的数据量
对哪个字段进行统计?求每一个表的总的记录数字?还是针对某列字段求和?还是?问题还是没有说清楚哦
如果你有其它意见或私下交流,请直接发送maledong_work@foxmail.com;或者
If you do not have QQ, please open the page and download it and click the image to talk or leave message for me.
下载MSDN桌面工具(Vista,Win7)
下载Technet桌面小工具(Vista,Win7)
慈善点击,点击此处 -
嗯,没有针对字段,是求每一个表的总的记录数字,最后得到的是这几个表的总的记录数字
给你提示:1)首先把某个数据库中全部的数据表读取出来
2)然后逐一查询多少记录即可。
比如:
List<string> tbnames = new List<string>();
using (SqlConnection con = new SqlConnection("你的连接字符串"))
{
SqlCommand cmd = new SqlCommand("select name from sysobjects where xtype='U ' and name<>'sysdiagrams' order by [name]",con);
con.Open();
SqlDataReader sr = cmd.ExecuteReader();
while(sr.Read())
{
tbnames.Add(sr["name"].ToString());
}
con.Close();
}
然后把全部的数据表逐一统计数据即可。
using (SqlConnection con = new SqlConnection("你的连接字符串"))
{
int totalCount = 0;
con.Open();
foreach(string s in tbnames)
{
SqlCommand cmd = new SqlCommand("select count(*) from "+ s,con);
totalCount +=(int)cmd.ExecuteScalar();
}
con.Close();
}
totalCount就是你要的表总数了。
如果你有其它意见或私下交流,请直接发送maledong_work@foxmail.com;或者
If you do not have QQ, please open the page and download it and click the image to talk or leave message for me.
下载MSDN桌面工具(Vista,Win7)
下载Technet桌面小工具(Vista,Win7)
慈善点击,点击此处- 已标记为答案 梁敬超 2011年10月11日 6:25
-
谢谢!!
不用谢!我的方法可能不是最好,只是给你一个思路。这个方法可以通用求出任意用户表的总共记录数。
如果你有其它意见或私下交流,请直接发送maledong_work@foxmail.com;或者
If you do not have QQ, please open the page and download it and click the image to talk or leave message for me.
下载MSDN桌面工具(Vista,Win7)
下载Technet桌面小工具(Vista,Win7)
慈善点击,点击此处