在asp.net中用SqlConnection方法取变量时,代码如下:   SqlConnection connect = new SqlConnection("server=localhost;uid=sa;password=;database=StudentsInfo");
   connect.Open();
   SqlDataAdapter adapter = new SqlDataAdapter();
   string s = "select PW from User1 where ID='123'";
   adapter.SelectCommand = new SqlCommand(s, connect);
   DataSet ds = new DataSet();
   adapter.Fill(ds);
   string s1 = ds.Tables[0].Rows[0][0];
     
   
  表User1 中有ID 和PW两条属性
   想把ID为“123”的PW属性赋给s1,为什么在赋值语句中有错误?
   显示无法将类型“object”隐式的转换为“string”类型
     
  新手,急求~~

解决方案 »

  1.   

    string s1 = ds.Tables[0].Rows[0][0].ToString();DataSet取出的值默认是object类型,要转换。
      

  2.   


    string s1 = ds.Tables[0].Rows[0][0].ToString();
      

  3.   


    这个也是不行啊  还是错误 
    说说的是无法将方法组“toString()转换为非委托类型“string”;”
      

  4.   


    这个也是不行啊  还是错误 
    说说的是无法将方法组“toString()转换为非委托类型“string”;”
      

  5.   


    SqlConnection connect = new SqlConnection("server=localhost;uid=sa;password=;database=StudentsInfo");
      connect.Open();
      string s = "select PW from User1 where ID='123'";
      SqlDataAdapter adapter = new SqlDataAdapter(s,connect);
      DataSet ds = new DataSet();
      adapter.Fill(ds);
      string s1 = ds.Tables[0].Rows[0]["PW"].ToString();