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

//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" ];
   }
}

你可能感兴趣的:(c#)