Stored Procedure with parameters into DataGridView in C# -


i'm new c# , want pull data sql database c# application in visual studios. have been using mix of guides cannot find wrong. code works if want recall table without specifying parameters otherwise fails.

this code currently:

string cs =  "server = server-sql1;database=accounts;trusted_connection=true"; using (sqlconnection con = new sqlconnection(cs)) {     sqlcommand cmd = new sqlcommand("asp_slinvoice", con);      //specify stored procedure , not normal proc     cmd.commandtype = system.data.commandtype.storedprocedure;      //list parameters required , should     cmd.parameters.addwithvalue("@varcurrency", "usd");     cmd.parameters.addwithvalue("@invstart", "0");     cmd.parameters.addwithvalue("@invend", "399999");     cmd.parameters.addwithvalue("@varcurrency", "0");      con.open();     cmd.executenonquery();      using(sqldataadapter adap = new sqldataadapter(cmd))     {         datatable dt = new datatable();         adap.fill(dt);         datagridview1.datasource = dt;     } } 

this error message get:

enter image description here

you define parameter twice!

cmd.parameters.addwithvalue("@varcurrency", "usd"); // #1 cmd.parameters.addwithvalue("@invstart", "0"); cmd.parameters.addwithvalue("@invend", "399999"); cmd.parameters.addwithvalue("@varcurrency", "0"); // #2 

remove 1 of them


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -