C#和我的查询中的编码是,
query = "select COUNT(*) as rowsCount from employee_leaves where PARTY_ID ='10'";
执行后,
OracleDataReader dr = command.ExecuteReader();
我现在如何计算int
我从数据库中获得的表有1行,其中包含3,
我试过这个,int i = dr["rowsCount"];
和此,int i = dr.GetInt32(0);
但没有成功。
答案 0 :(得分:1)
假设你用c#编码。请在dr.Read()
之前使用(它应该返回true),然后使用dr从第一行读取值。
答案 1 :(得分:1)
由于您只需要获取一个值,因此请使用ExecuteScalar()
。实施例
string sqlQuery = "select COUNT(*) as rowsCount from employee_leaves where PARTY_ID ='10'";
OracleCommand command = new OracleCommand(sqlQuery, connection);
// other codes here such as opening the connection
int count = Convert.ToInt32(command.ExecuteScalar());