第2个回答 2008-12-27
public int getcount()
{
string sqlconn="server=(local);uid=wangzi;pwd=45789022;database=db;";
string sql="select count(BookId) from book ";
SqlConnection conn = new SqlConnection(sqlconn);
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
int a = 0;
SqlDataReader dr = null;
try
{
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (dr.Read())
{
a= dr.GetInt32(0);
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return a;
}
刚才特意写了一个 呵呵 应该符合你胃口吧?