从数据库SELECT一个数据,怎么把它赋值给变量?

if(!IsPostBack)  
  {  
  string   dsn   =   ConfigurationSettings.AppSettings["TRS"];  
  SqlConnection   myConnection   =   new   SqlConnection(dsn);  
  string   mySelectQuery="select   a.shopcode,a.shopname,a.shopchief,a.shopphone,a.shopfax,   a.setupdate,a.memo,a.shopaddress,b.areaname   from   Shopdata   as   a   left   outer   join   area   as   b   on   a.areacode=b.areacode   where   a.ShopCode=''"+ShopCode+"''";  
  SqlCommand   cmd=new   SqlCommand(mySelectQuery,myConnection)   ;  
  myConnection.Open   ();  
  SqlDataReader   dr=cmd.ExecuteReader();  
  while(dr.Read())  
  {  
  lbCode.Text=dr["shopcode"].ToString();  
  txtName.Text=dr["shopname"].ToString();  
  txtChief.Text=dr["shopchief"].ToString();  
  DateTimeBox1.Text   =dr["setupdate"].ToString();  
  ddlArea.SelectedItem.Text=dr["areaname"].ToString();  
  txtAddress.Text=dr["shopaddress"].ToString();  
  txtFax.Text=dr["shopfax"].ToString();  
  txtMemo.Text=dr["memo"].ToString();  
  txtPhone.Text   =dr["shopphone"].ToString();  
   
  
  }  
  dr.Close   ();  
  cmd.Dispose   ();  
  myConnection.Close   ();  
   
  }  

你可能感兴趣的:(select)