c# - Populate a datagridview from database on selection of an item in combobox -


i have combobox having requisition number. when select 1 of requisition item r001 in combobox information should populated in datagrid below. have used stroed procedure this. dont know how bind datagrid view control info.

code:

private void cmbreqno_selectedindexchanged(object sender, eventargs e)     {          cmd.connection = con;         if (con.state != connectionstate.open)         {             con.open();         }          txtcc.text = "";         int selection = convert.toint16(((keyvaluepair<string, string>)(cmbreqno.selecteditem)).key);         if (selection.tostring() != "")         {              cmd.connection = con;             cmd.commandtype = commandtype.storedprocedure;             cmd.commandtext = "itemname";             cmd.parameters.addwithvalue("@req_no", selection);             dsitemname.clear();             adp = new sqldataadapter(cmd);             adp.fill(dsitemname);             txtcc.text = dsitemname.tables[1].rows[0]["costcenter_no"].tostring();             txtcc.tag = dsitemname.tables[1].rows[0]["costcenter_id"].tostring();              cmd.parameters.clear(); } 

stored procedure:

alter proc itemname (     @req_no int ) begin select item_name,brand_name,quantity,requisitionitem.item_cost requisitionitem left outer join item on requisitionitem.item_id=item.item_id requisitionitem.req_no=@req_no end 

just databind datatable datagridview

datagridview1.datasource = null; //clear old 1 datagridview1.rows.clear(); //remove old rows datagridview1.datasource = dsitemname.tables[0]; 

Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -