请教一条SQL语句

来源:百度知道 编辑:UC知道 时间:2024/06/17 20:22:57
select count(*) from student where 姓名=‘张三’,这条语句的意思是查询所有姓名为‘张三’的学生有多少个。我想请教的是,查询完毕后,这条语句的返回结果是什么,结果我该如何获得呢?

返回的是个数字类型的整数

不知道你想用什么语言去获取

这里给你个c#的获取吧:

string conn="Provider=SQLNCLI;Server=localhost\\SQLEXPRESS;Database=CDROM_LawContract;UID=sa;PWD=sa;";
string sql="select count(*) from student where 姓名=‘张三’";
int countNum=GetCount(conn,sql);
public int GetCount(string conn,string Sql)
{
try
{
OleDbConnection myConnection = new OleDbConnection(conn);
OleDbCommand myCommand = new OleDbCommand(Sql, myConnection);

myConnection.Open();
OleDbDataReader result = myCommand.ExecuteReader();
int i = 0;
while (result.Read())
{
i = result.GetInt32(0);
//i=result.;
}
result.Close();
myCommand.Dispose();