I have a method which returns DataSet.
protected DataSet GetProgramList()
{
DataSet ds1 = new DataSet();
using (SqlConnection cn = new SqlConnection("server=Daffodils-PC\\sqlexpress;Database=Assignment1;Trusted_Connection=Yes;"))
{
using (SqlDataAdapter da = new SqlDataAdapter(@"SELECT * FROM Program", cn))
da.Fill(ds1, "Program");
}
return ds1;
}
I want to use a specific column from the DataSet in other Method which is below:
protected DataSet GetStudentByProgramID(int programID)
{
DataSet ds2 = new DataSet();
using (SqlConnection cn = new SqlConnection("server=Daffodils-PC\\sqlexpress;Database=Assignment1;Trusted_Connection=Yes;"))
{
using (SqlDataAdapter da = new SqlDataAdapter(@"SELECT LastName, FirstName FROM Student JOIN Program on Program.ProgramID = Student.ProgramID WHERE ProgramID ="+programID, cn))
da.Fill(ds2, "Student");
}
return ds2;
}
For example I want to use, the column ProgramID from Program Table in first method. I know I have to store the returned dataset in a variable but How?
Given that you will have
ds1accessible forGetStudentByProgramIDmethodThen you can use it this way