ADO之command

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();//要进行类型转换

posted @ 2015-12-29 15:15  小蚂蚁zoe  阅读(248)  评论(0编辑  收藏  举报