Fill a datagrid from another class
Posted on 2004-09-15
I hope somebody can show me how to do this please.
I need to use a dataset and not a datareader for this part of my application and I'm using OO techniques for my web application.
I currently have a page_load event that goes off the a class and returns the results of a datareader as follows:-
/// Summary description for Scores.
public class Scores : System.Web.UI.Page
public void Page_Load(object sender, System.EventArgs e)
//Set the title of the page to the member name
string FName = Request.QueryString["Name"];
string LastName = Request.QueryString["LastName"];
string MemberID = Request.QueryString["MemberID"];
lblName.Text = FName + " " + LastName;
lblFname.Text = FName;
lblLname.Text = LastName;
lblMemberID.Text = MemberID;
BMRC3.GetScores scores = new BMRC3.GetScores();
dgScores.DataSource = scores.myScores(LastName);
Here is the class that gets called from the code above:-
public class GetScores
public string LastName;
public SqlDataReader myScores(string LastName)
//This section retrieves the scores in the database and returns them
//to the calling procedure which displays them in the datagrid dgScores
//This event is called from the scores page_load event
//Create The Connection String
SqlConnection myConnection = new SqlConnection(ConfigurationSettings. AppSettings["ConnectionString"]);
//Create the SQL command
SqlCommand command = new SqlCommand("MemberSpecific", myConnection);
// Mark the Command as a SPROC
command.CommandType = CommandType.StoredProcedure;
//Set the input parameters
SqlParameter parameter1 = new SqlParameter("@Lastname", SqlDbType.NVarChar, 50);
parameter1.Value = LastName;
SqlDataReader result = command.ExecuteReader(CommandBehavior.CloseConnection);
HERE'S WHAT I NEED...............
I need to do the same sort of thing to fill my datagrid but I need to use a dataset and not a datareader...
COuld somebody please show me how to code this up correctly so the LastName parameter is passed to my stored procedure, a data adapter is filled and then on my calling page, I can bind to my datagrid from the dataset