将数据集分配给局部变量

Assign DataSet to Local Variables

我是 运行 一个 SQL 查询并返回一个 DataSet - 我想迭代 DataSet 中的信息并将值分配给局部变量。我已经确认我的 DataSet returns 行,但由于某种原因我的变量没有被分配。有人可以看看我的语法并帮助解释为什么会这样吗?

protected void GetSomeData()
{
  string employeeid = this.txtemployeeid.Text;
  DataSet empinfo = new DataSet();
  empinfo = RunSqlQuery(employeeid);
  this.txtemployeefirstname = empinfo.Tables[0].Rows[0]["employeefirstname"].ToString());
  this.txtemployeelastname = empinfo.Tables[0].Rows[1]["employeelastname"].ToString());
  this.txtemployeeaddress = empinfo.Tables[0].Rows[2]["employeeaddress"].ToString());
  this.txt.employeephone = empinfo.Tables[0].Rows[3]["employeephone"].ToString());
}
public DataSet RunSqlQuery(string employeeid)
{
  string sqlQuery = "Select employeefirstname, employeelastname, employeeaddress, employeephone from abcd where employeeid = "+employeeid+" and employeeid is not null";
  try
  {             
      connectionString = System.Configuration.ConfigurationManager.AppSettings[connectionString].ToString();   
      sqlDatabaseConnection = new SqlConnection(connectionString);
      sqlCommand = new SqlCommand(sqlQuery, sqlDatabaseConnection);
      sqlDatabaseConnection.Open();
      sqlCommand.CommandTimeout = 0;        
      dataSet = new DataSet();
      sqlDataAdapter = new SqlDataAdapter(sqlCommand);            
      sqlDataAdapter.Fill(dataSet, "Data");
      return dataSet;
  }
  catch (Exception exception)
  {
      throw exception;
  }
  finally
  {
      sqlDatabaseConnection.Close();
      sqlCommand.Dispose();
      sqlDataAdapter.Dispose();
  }

}

编辑
通过未分配变量,我的意思是当我单步执行我的代码时,似乎从数据库返回的值没有被填充到 empinfo.Tables[0].Rows[0]["employeefirstname"].ToString()); 它们总是空的。

您正在将值分配给文本框(至少,我假设 txtemployeefirstname 是一个文本框)。我想你的意思是 txtemployeefirstname.text?