c# - Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource -
i have function dropdownlist , should run store procedure , supplires names taht should displayes @ dropdownlsit .
this function :
public void loadsuppliers(dropdownlist ddl , int num) { con = connect("igroup9_test1connectionstring"); using (sqlcommand sqlcomm = new sqlcommand("[spgetsuppliers]", con)) { if (con.state != connectionstate.open) { con.open(); } try { sqlcomm.commandtype = commandtype.storedprocedure; sqlcomm.parameters.addwithvalue("@rowmeterialid ", num); sqlcomm.commandtimeout = 600; ddl.datasource = sqlcomm; sqlcomm.executenonquery(); ddl.databind(); ddl.datatextfield = "sname"; ddl.datavaluefield = "sname"; } catch (exception ex) { throw (ex); } } }
and procedure:
use [igroup9_test1] go /****** object: storedprocedure [dbo].[spgetsuppliers] script date: 03/24/2014 18:13:12 ******/ set ansi_nulls on go set quoted_identifier on go alter proc [dbo].[spgetsuppliers] ( @rowmeterialid int ) begin select distinct sname supplier, rawmaterials, supplierrawmaterials rawmaterials.rmid=@rowmeterialid , rawmaterials.rmid=supplierrawmaterials.rmid , supplierrawmaterials.supplierid=supplier.supplierid end
when i'm running program throw error:
system.invalidoperationexception: data source invalid type. must either ilistsource, ienumerable, or idatasource.
you cannot assign ddl.datasource = sqlcomm
since sqlcommand.
fill dataset
, assign
ddl.datasource = dsmyresult;
Comments
Post a Comment