如何在c#中统计sql表的行数? 我需要从我的数据库中提取一些数据...
最佳答案
你可以这样尝试:
select count(*) from tablename where columname = 'values'
C# 代码将是这样的:-
public int A()
{
string stmt = "SELECT COUNT(*) FROM dbo.tablename";
int count = 0;
using(SqlConnection thisConnection = new SqlConnection("Data Source=DATASOURCE"))
{
using(SqlCommand cmdCount = new SqlCommand(stmt, thisConnection))
{
thisConnection.Open();
count = (int)cmdCount.ExecuteScalar();
}
}
return count;
}
关于c# - C#如何计算sql表的行数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20160928/