I am coding in C#, visual studio 2005. I sucessfully created the data for my datagrid. I created the connection string, an adapter, dataset and filled the dataset before binding to the mainGrid.
I created a detailsView in the (I still have more to do with this application, like update, and remove) and repeated the same actions. only with my adapter, i have a parameter. However, when i run the app, I get:
"Expects Parameter which was not supplied"
How would I supply the parameter?
===========This is my code-behind: =====================
public partial class ReqsDubs : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ bindGrid();
}
}
private void bindGrid()
{
string tapelibraryconn = ConfigurationManager.ConnectionStrings["tapelibraryconn"].ConnectionString;
//create dataset
DataSet ds = new DataSet();
//create the connection string
SqlConnection conn = new SqlConnection(tapelibraryconn);
//create adapter
SqlDataAdapter myadap = new SqlDataAdapter("select ID as [Request ID], Name, [Request date] from view_DubRequests WHERE Status = 1", conn);
//fill the dataset
myadap.Fill(ds, "view_DubRequests");
mainGrid.DataSource = ds;
mainGrid.DataBind();
}
//this works fine
protected void mainGrid_SelectedIndexChanged(object sender, EventArgs e)
{
//obtain the index of the selected table
int selectedRowIndex;
selectedRowIndex = mainGrid.SelectedIndex;
//get information about record selected
GridViewRow row = mainGrid.Rows[selectedRowIndex];
//Old Code that worked to show the data before defining a new connection
/*string name = row.Cells[3].Text;
string showID = row.Cells[4].Text;
errorLbl.Text = "Tomeka, you selected " + showID + "'s " + name + " record for editing" ;
*/
//read the ID
int RequestID = System.Convert.ToInt16(mainGrid.SelectedRow.Cells[3].Text.ToString());
//define the data objects
string mytapelibraryconn = ConfigurationManager.ConnectionStrings["tapelibraryconn"].ConnectionString;
SqlConnection myConn = new SqlConnection(mytapelibraryconn);
//command object
SqlCommand myComm = new SqlCommand("Select RequestID, User, Email, Show, Number, Barcode FROM view_DubReqsDetails where RequestID=@RequestID", myConn);
myComm.Parameters.Add("@RequestID", SqlDbType.Int, 4);
//create adapter
SqlDataAdapter adap = new SqlDataAdapter(myComm);
//create new dataset to connect the controls
DataSet da = new DataSet();
adap.Fill(da);
ReqDetails.DataSource = da;
ReqDetails.DataBind();
//fill the adapter and bind to detailsGrid
adap.SelectCommand = myComm;
}
}
I created a detailsView in the (I still have more to do with this application, like update, and remove) and repeated the same actions. only with my adapter, i have a parameter. However, when i run the app, I get:
"Expects Parameter which was not supplied"
How would I supply the parameter?
===========This is my code-behind: =====================
public partial class ReqsDubs : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ bindGrid();
}
}
private void bindGrid()
{
string tapelibraryconn = ConfigurationManager.ConnectionStrings["tapelibraryconn"].ConnectionString;
//create dataset
DataSet ds = new DataSet();
//create the connection string
SqlConnection conn = new SqlConnection(tapelibraryconn);
//create adapter
SqlDataAdapter myadap = new SqlDataAdapter("select ID as [Request ID], Name, [Request date] from view_DubRequests WHERE Status = 1", conn);
//fill the dataset
myadap.Fill(ds, "view_DubRequests");
mainGrid.DataSource = ds;
mainGrid.DataBind();
}
//this works fine
protected void mainGrid_SelectedIndexChanged(object sender, EventArgs e)
{
//obtain the index of the selected table
int selectedRowIndex;
selectedRowIndex = mainGrid.SelectedIndex;
//get information about record selected
GridViewRow row = mainGrid.Rows[selectedRowIndex];
//Old Code that worked to show the data before defining a new connection
/*string name = row.Cells[3].Text;
string showID = row.Cells[4].Text;
errorLbl.Text = "Tomeka, you selected " + showID + "'s " + name + " record for editing" ;
*/
//read the ID
int RequestID = System.Convert.ToInt16(mainGrid.SelectedRow.Cells[3].Text.ToString());
//define the data objects
string mytapelibraryconn = ConfigurationManager.ConnectionStrings["tapelibraryconn"].ConnectionString;
SqlConnection myConn = new SqlConnection(mytapelibraryconn);
//command object
SqlCommand myComm = new SqlCommand("Select RequestID, User, Email, Show, Number, Barcode FROM view_DubReqsDetails where RequestID=@RequestID", myConn);
myComm.Parameters.Add("@RequestID", SqlDbType.Int, 4);
//create adapter
SqlDataAdapter adap = new SqlDataAdapter(myComm);
//create new dataset to connect the controls
DataSet da = new DataSet();
adap.Fill(da);
ReqDetails.DataSource = da;
ReqDetails.DataBind();
//fill the adapter and bind to detailsGrid
adap.SelectCommand = myComm;
}
}