Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to supply parameter for detailsView

Status
Not open for further replies.

radiance

Programmer
Jan 4, 2003
164
US
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;

}
}

 
It doesn't look like you are specifying a value for the RequestID parameter object.

Code:
myComm.Parameters["@RequestID"].Value = RequestID;

 
I have:

myComm.Parameters.Add("@RequestID", SqlDbType.Int, 4);

is this what you mean?
 
I think
Code:
myComm.Parameters.Add("@RequestID", SqlDbType.Int, 4);
is only specifying the parameter name, the data type, and the size of the data type. You still need to supply the value, which I am assuming is the RequestID variable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top