zoukankan      html  css  js  c++  java
  • SqlCommand类

    SqlCommand的方法:

    1.ExecuteNonQuery();

      它的返回值类型为int型。多用于执行增加,删除,修改数据。返回受影响的行数。

    2.ExecuteReader();

      它的返回类型为SqlDataReader。此方法用于用户进行的查询操作。使用SqlDataReader对象的Read();方法进行逐行读取。

    例如:

     

      SqlCommand comm =new SqlCommand("select * from CGSZ where cid="+id,conn);

     

      SqlDataReader reder=comm.ExecuteReader();

     

      while(reder.Read())

     

      {

     

      //读出内容列

     

      string str=reder["cname"].ToString();

     

      //读取分类列

     

      string str1=reder["ckind"].ToString();

     

      //分别为文本框加载数据

     

      this.txtContent.Text = str;

     

      this.txtClass.Text = str1;

     

      }

     

      其中的读取数据列的时候。除了使用reader["列名"].ToString();还可以使用reader[索引].ToSting();<注意:这里的索引指的是数据库中列的索引。从0开始。>

    3.ExecuteScaler();

      它的返回值类型多位int类型。它返回的多为执行select查询。得到的返回结果为一个值的情况,比如使用count函数求表中记录个数或者使用sum函数求和等。

     
     
  • 相关阅读:
    [codevs2800]送外卖
    python JSON处理
    python系统编码格式
    python,django,mysql版本号查询
    django开发总结:
    python之---类和实例
    django Q和F查询
    合并多个python list以及合并多个 django QuerySet 的方法
    python学习之---匿名函数,返回函数,偏函数
    python学习之---生成器
  • 原文地址:https://www.cnblogs.com/Eleanore/p/2518204.html
Copyright © 2011-2022 走看看