zoukankan      html  css  js  c++  java
  • 用DataReader读取数据

    DataReader读取数据步骤

      1、连接数据源

      2、打开连接

      3、发出一个SQL查询命令

      4、使用DataReader读取并显示数据

      5、关闭DataReader和连接

    代码如下:

            private void DataReaderUse()
            {
                
    //1、建立连接
                SqlConnection thisConnection = new SqlConnection(sSqlConnection);
                
    //2、打开连接
                thisConnection.Open();

                
    //建立SQL查询
                SqlCommand thisCommand = thisConnection.CreateCommand();
                
    //3、输入查询语句
                thisCommand.CommandText = "select customerID,companyName from customers";

                
    //建立读取
                SqlDataReader thisReader = thisCommand.ExecuteReader();

                tbValue.Text 
    = "CustomerID" + "CompanyName";
                
    //4、查询并显示数据
                while (thisReader.Read())
                {
                    tbValue.Text 
    += "\r\t";
                    tbValue.Text 
    += thisReader["CustomerID"].ToString().PadRight(10' ');
                    tbValue.Text 
    += thisReader["CustomerID"].ToString();
                }
                
    //5、关闭连接
                thisReader.Close();
                thisConnection.Close();
            }
  • 相关阅读:
    解决Xcode 7编译错误:does not contain bitcode
    iOS无处不在详解iOS集成第三方登录(SSO授权登录无需密码)
    iOS- 如何集成支付宝
    99.Recover Binary Search Tree
    101.Symmetric Tree
    108.Convert Sorted Array to Binary Search Tree
    242.Valid Anagram
    292.Nim Game
    872.Leaf-Similar Trees
    HDU-1390 Binary Numbers
  • 原文地址:https://www.cnblogs.com/scottckt/p/1260447.html
Copyright © 2011-2022 走看看