C#SqlDataReader读取数据库
1、打开sqlserver 2008 新建一个geek的数据库.
再新建一个表_登录 字段如图中.


2、打开visual studio新建一个Windows窗体应用程序.

3、拖拉几个控件,位置如图.

4、//在查询下面写如下代码
string 连接字符串 = @"server=.;database=geek;Integrated Security=true";
string sql = "select * from 表_登录 where id >@id;";
SqlParameter 参数_用户名 = new SqlParameter("@id", textBox_id.Text);
using (SqlConnection 连接对象 = new SqlConnection(连接字符串))
{
using (SqlCommand 执行对象 = new SqlCommand(sql, 连接对象))
{
执行对象.Parameters.Add(参数_用户名);
连接对象.Open();
using (SqlDataReader 读取对象 = 执行对象.ExecuteReader())
{
textBox_数据.Text = null;
while (读取对象.Read())
{
for (int i = 0; i < 读取对象.FieldCount; i++)
{
textBox_数据.AppendText(读取对象[i].ToString());
}
textBox_数据.AppendText("\r\n");
}
}
}
}

5、输入1查询一下.

6、输入5查询一下.
这样子我们就得到了我们想要的查询结果.
