需要说明的是,我使用的是sql server 2000为服务器。 按照以下的几步,就可以很顺利的连接到服务器,执行基本的sql操作了。 第一步 连接服务器 第二步 新建命令 SqlCommand thiscommand = thisConnection.CreateCommand(); 第三步 给问题文本赋值 thiscommand.CommandText = "insert into Users(Telephone) values('02787546321')" 这里的字符串就是需要执行的sql命令 第四步 执行命令 分为三种命令,相应调用不同的方法: 1 不需要查询的(插入,更新,删除) thiscommand.ExecuteNonQuery(); 该函数会返回收到影响的总行数。 2 只需要查询一个值的 thiscommand.ExecuteScalar(); 该函数会返回使用的sql语言查询的结果 3 需要同时查询得到多个值的 SqlDataReader QuesReader = thiscommand.ExecuteReader(); //新建一个SqlDataReader 第五步 关闭连接 thisConnection.Close(); |
|