c#获取数据库中某一行的数据

来源:互联网 发布:数据库关系 0 1 编辑:程序博客网 时间:2024/06/05 02:03
//1.构建数据库查询语句,X为你所查询的值所在的列名,table 为你保存数据的表名。根据某列的值等于Y查询出X;
string sql = "select x from [table] where [column] = Y"
//2.投递数据库查询 _connstring 为数据库连接字符串
SqlConnection conn = new SqlConnection(_connstring);
SqlCommand command = new SqlCommand(sql, conn);
//3.执行数据库查询获取返回值
use(conn)
{
  conn.Open();
  SqlDataReader reader = command.ExecuteReader();
  while(reader.read())
  {
    int xValue = (int)reader["X"];
  }
}
阅读全文
0 0
原创粉丝点击