Might be best if I give an example. I'm wondering if I can use the one
dataadapter for 2 different calls to the same sproc, and/or how I can use
less code:
// Open a connection to database
SqlConnection objConn = new
SqlConnection(ConfigurationSettings.AppSettings["connJBS"]);
//create dataset to hold all table rows
DataSet objDSJobTypes = new DataSet("JobTypes");
//Web Jobs
//Create the stored procedure command object & add parameter objects for
the stored procedure parameter
SqlCommand objCmdWebJobs = new SqlCommand("spTFL_RequestJob_JobTypes",
objConn);
objCmdWebJobs.CommandType = CommandType.StoredProcedure;
objCmdWebJobs.Parameters.Add("@JobCatID", SqlDbType.Int);
objCmdWebJobs.Parameters["@JobCatID"].Value = 1;
//create our DataAdapter object and use it to fill the dataset object
SqlDataAdapter objDAWebJobs = new SqlDataAdapter(objCmdWebJobs);
objDAWebJobs.Fill(objDSJobTypes,"WebJobs");
//bind to repeater
Repeater1.DataSource=objDSJobTypes.Tables["WebJobs"].DefaultView;
Repeater1.DataBind();
//Web Projects
//Create the stored procedure command object & add parameter objects for
the stored procedure parameter
SqlCommand objCmdWebProjects = new
SqlCommand("spTFL_RequestJob_JobTypes", objConn);
objCmdWebProjects.CommandType = CommandType.StoredProcedure;
objCmdWebProjects.Parameters.Add("@JobCatID", SqlDbType.Int);
objCmdWebProjects.Parameters["@JobCatID"].Value = 2;
//create our DataAdapter object and use it to fill the dataset object
SqlDataAdapter objDAWebProjects = new SqlDataAdapter(objCmdWebProjects);
objDAWebProjects.Fill(objDSJobTypes,"WebProjects");
//bind to repeater
Repeater2.DataSource=objDSJobTypes.Tables["WebProjects"].DefaultView;
Repeater2.DataTextField = "JobTypeDesc";
Repeater2.DataValueField = "JobTypeID";
Repeater2.DataBind();
Any advice greatly appreciated.
Thanks
Matt
Karl Seguin said:
Not sure what you are asking about about the parameters.
If you are using an sproc (as you indicated) you'd pass in all the
parameters needed for both query to a single sproc and the queries can
use them as needed.
If you want to refer to the tables by name, simply name them after you've
done the fill based on the index (so use the index the first time, then
the name).
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)