小试一下:
string connectionString= @
"data source=localhost;Initial catalog=(数据库名);integrated security=SSPI";//连接数据库
string commandString="select
*
from 表 ";//sql 语句
SqlDataAdapter
myAdapter=new SqlDataAdapter(commandString,connectionString);//适配器即DataSet和数据源的桥梁,用于DataSet的DataTable对象和SQl语句的返回结果之间交换数据
DataSet myDataset=new DataSet();//存储数据
myAdapter.Fill(myDataset,"表");//填充数据
DataTable myTable=myDataset.Tables["表"];
int count=myTables.Rows.Count;/////////计算记录的条数
Console.WriteLine("Rows{0}",count);