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:

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
Post a Comment