using System.Data.SqlClient;//引用此命名空间
//编写连接字符串
string sql = "server=.;database=Data0504;user=sa;pwd=123;";
//创建数据库连接对象
SqlConnection conn = new SqlConnection(sql);
//创建数据库操作对象
SqlCommand cmd = conn.CreateCommand();
//执行操作
cmd.CommandText = "select *from Users";
conn.Open();//打开数据库连接
SqlDataReader dr = cmd.ExecuteReader();//将语句执行,结果查询到dr对象中
Console.WriteLine("id 编号 用户名 密码 昵称 性别 生日 民族");
while (dr.Read())
{
Console.WriteLine(dr["Ids"] + " | " + dr["Ucode"] + " | " + dr["UserName"] + " | " + dr["PassWord"] + " | " + dr["NickName"] + " | " + (Convert.ToBoolean(dr["Sex"]) ? "男" : "女") + " | " + Convert.ToDateTime(dr["Birthday"]).ToString("yyyy年MM月dd日") + " | " + dr["Nation"]);
}
conn.Close();//关闭数据库连接
Console.ReadLine();