Toys 玩具表
字段 数据类型 描述
ToyId int 玩具编号
ToyName char(20) 玩具名称
ToyRate money 玩具价格
利用SqlConnection,SqlCommand,SqlDataReader等输出整张表的数据

解决方案 »

  1.   

    string strConn=""//获取配置文件的连接字符串
    SqlConnection conn=new SqlConnection(strConn)
     if (conn.State != ConnectionState.Open)
      {
         conn.Open();
      }
    sqlCommand cmd=new SqlCommand();
    cmd.Connection = conn;
    command.CommandText = "select * from Toys";
    command.CommandType = CommandType.Text;
    using(SqlDataReader dr=cmd.ExecuteReader())
    {
       while(dr.Read())
       {
           //存入数据
       }
    }
    conn.close();
      

  2.   

    cmd.CommandText = "select * from Toys";
    cmd.CommandType = CommandType.Text;
      

  3.   

    SQL语句为:
    SELECT * FROM Toys ORDER BY ToyId 
    使用的函数为SqlDataReader,通过while循环获取整张表的数据