Connection c = new Connection();
public string checkIfExists(string Name)
{
string sql = "SELECT * FROM users WHERE name = '" + name + "'";
c.Execute(sql);
return "";
}
c.Execute(sql)正在调用SqlCommand函数来执行sql查询。
我想知道如何计算此查询检索到的行数。
忽略回报。
答案 0 :(得分:7)
COUNT
ExecuteScalar
检索答案查询应如下所示:
var sql = "SELECT COUNT(*) FROM users WHERE name = @Name";
答案 1 :(得分:3)
这是Sam SQL查询:
SELECT COUNT(1) FROM nazvaniyami
SQL query with condition:
SELECT COUNT(1) FROM nazvaniyami WHERE condition
Implementation in PHP:
$a = mysql_query("SELECT COUNT(1) FROM navaneetham");
$b = mysql_fetch_array( $a );
echo $b[0]; // prints the number of rows
同样,可以添加条件。然后代码打印满足条件的表中的行数。 谢谢你的关注,你是Maxim