connection      command对象使用的数据库连接

commandText     执行的SQL语句

ExecuteNonQuery  执行不返回行的语句,如UPDATE等

ExecuteReader    返回DateReader对象

ExecuteScalar    返回单个值,如执行COUNT(*)

使用Command步骤

1.创建数据库连接

2.定义SQL语句

3.创建Command对象

4.执行命令

sqlconnection connection = new sqlconnection(connstring);

string sql = "select count(*) from Admin where loginid=' " + username +" ' and loginpwd=' " +pwd+" ' ";

connection.open();//打开数据库连接

sqlcommand command = new sqlcommand(sql,connection);

int num = (int)command.ExecuteScalar();//要进行类型转换

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2022-12-23
  • 2021-09-19
  • 2021-06-18
猜你喜欢
  • 2022-12-23
  • 2021-05-16
  • 2021-09-07
  • 2021-08-11
  • 2021-12-18
  • 2022-01-17
相关资源
相似解决方案