Toys 玩具表
字段 数据类型 描述
ToyId int 玩具编号
ToyName char(20) 玩具名称
ToyRate money 玩具价格
利用SqlConnection,SqlCommand,SqlDataReader等输出整张表的数据
字段 数据类型 描述
ToyId int 玩具编号
ToyName char(20) 玩具名称
ToyRate money 玩具价格
利用SqlConnection,SqlCommand,SqlDataReader等输出整张表的数据
调试欢乐多
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();
cmd.CommandType = CommandType.Text;
SELECT * FROM Toys ORDER BY ToyId
使用的函数为SqlDataReader,通过while循环获取整张表的数据