how to from select parameterized query in asp.net -


i want write parametrized query select statement. gives exception "must declare variable '@'." how declare variable .

my code given below:

sqlconnection con = null;         sqlcommand cmd = null;         try         {             //int @[month_for], @[year_for];             con = new sqlconnection("data source=192.168.10.3;initial catalog=gpstrainees;user id=gp;password=gp");             con.open();             string select = @"select [component_name] ,[component_amount]                              [goalplanfortrainees].[gp].[team_funds_details]                              [month_for] = @[month_for] , [year_for] = @[year_for]";             cmd = new sqlcommand(select, con);             cmd.parameters.add(new sqlparameter("@[month_for]", convert.toint32( textbox1.text.trim())));             cmd.parameters.add(new sqlparameter("@[year_for]",convert.toint32(textbox2.text.trim())));             dataset ds = new dataset();             sqldataadapter adp = new sqldataadapter(select, con);             adp.fill(ds);             gridview1.datasource = ds;             gridview1.databind();         }         catch (exception ex)         {         }                 {             if (con != null)             {                 con.close();             }         }`enter code here` 

while creating parameters, please remove "@" in front of parameter name. this:

cmd.parameters.add(new sqlparameter("[month_for]", convert.toint32(textbox1.text.trim())));  

hopefully should help.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -