如
string SQL = "select count(*) from abc where id=1";
OleDbConnection Myconn = new OleDbConnection(MyConnString);
OleDbCommand Mycomm = new OleDbCommand(SQL,Myconn);
Mycomm.Connection.Open();
OleDbDataReader dr = Mycomm.ExecuteReader();
1.我想获得id为1的记录的数量,接下来程序里该怎么写呢?万分感谢!
string SQL = "select count(*) from abc where id=1";
OleDbConnection Myconn = new OleDbConnection(MyConnString);
OleDbCommand Mycomm = new OleDbCommand(SQL,Myconn);
Mycomm.Connection.Open();
OleDbDataReader dr = Mycomm.ExecuteReader();
1.我想获得id为1的记录的数量,接下来程序里该怎么写呢?万分感谢!
OleDbConnection Myconn = new OleDbConnection(MyConnString);
OleDbCommand Mycomm = new OleDbCommand(SQL,Myconn);
Mycomm.Connection.Open();
OleDbDataReader dr = Mycomm.ExecuteReader();if(dr.Read())
{
int tmp = Convert.ToInt32(dr[0]);
}
string SQL = "select count(*) from abc where id=1";
OleDbConnection Myconn = new OleDbConnection(MyConnString);
OleDbCommand Mycomm = new OleDbCommand(SQL,Myconn);
Mycomm.Connection.Open();
count= Mycomm.ExecuteScalar();
这样执行效率要高,而且获取就一个值。
如何才能获得select count(*) from abc where id=1的记录数量阿?
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = yourconnection;
myCommand.CommandType = CommandType.Text;
myCommand.CommandText = str;
myCommand.Connection.Close();
myCommand.Connection.Open();
string num = myCommand.ExecuteScalar().ToString();
Page.RegisterStartupScript("check", "<script>alert('记录数量为+num');</script>");
那个string str = "select max(xx) from xxx";
是 string str = "select count(xx) from xxx";
然后在结果集里取值
这个是不是哦?????