我正在使用存储过程对象执行一个查询。我想在执行查询后检索 Select 语句中返回的行数。
我在使用之间感到困惑ExecuteReader() & ExecuteScalar()
public static int getDuplicateEvent(string ATM, string Fault1, string Fault2, ref SqlConnection Connection)
{
string sQuery = "";
int result = 0;
try
{
sQuery = /*Query With Format Select Code From A Union Select Code From B */
using (SqlStoredProcedure sspObj = new SqlStoredProcedure(sQuery, Connection, CommandType.Text))
{
result = (int)sspObj.ExecuteScalar();
sspObj.Dispose();
}
}
catch (Exception xObj)
{
result = 0;
}
return result;
}