日期:2014-05-19  浏览次数:20696 次

数据库的菜鸟问题
查询所有表的语句sqlselect   name,count(*)   from   sysobjects   where   xtype   =   'u '
我用ADO.NET操作!
请问我用sqlcommand执行后的结果保存在哪?
比如我想要把表的数量赋给int   n;
表的名字赋给字符串数组 string   []   tablename;
怎么样才能赋给n和tablename


------解决方案--------------------
string [] tablename;放表的名字?那tablename.length不就是表的个数吗?不要用n了。sqlcommand你可以看下msdn帮助文档.
------解决方案--------------------
1、不能select name,count(*) from sysobjects where xtype = 'u '
count为非单组分组函数

如LS,得到string [] tablename后就可得到n了
------解决方案--------------------
public DataSet DataBaseSelect(String strSQL)
{
SqlConnection conn;
SqlDataAdapter apater;
DataSet dstResult;

SqlConnection conn = new SqlConnection( "server=localhost;database=pubs;uid=sa;pwd= ");
conn.open();
apater = New SqlDataAdapter(strSQL, conn);
dstResult = New DataSet();
apater.Fill(dstResult);
return dstResult;
}


int n;
DataSet ds = new DataSet();
ds = DataBaseSelect( "select name,count(*) from sysobjects where xtype = 'u ' ");
n = ds.Tables[0].rows[0].items[1];

tablename这个String数组的话循环一下这个DataSet赋一下值就可以了