sql server - Error using prepared statements in C# -


the parameters aren't add sql string, i'm doing wrong?

sqlcommand comando = conexao.createcommand(); comando.commandtimeout = 7200; foreach (sqlparameter parametro in parametros) {     comando.parameters.add(new sqlparameter(parametro.parametername, parametro.value)); }  comando.commandtext = cmdsql; comando.commandtype = commandtype.text; datatable dt = new datatable(); sqldataadapter adapter = new sqldataadapter(); adapter.selectcommand = comando;  try {     adapter.fill(dt); } catch (exception ex) { console.write(ex.message); } conexao.close();  return dt; 

the sql string, method call method above.

string cmdsql = "select top @quantidade *  representante"; sqlparametercollection sqlparameters = new sqlcommand().parameters; sqlparameters.addwithvalue("@quantidade", sqldbtype.int).value = quantidade;  return persistencia.persistencia.consultacomando(cmdsql, sqlparameters); 

thanks helping solution use string cmdsql = "select top (@quantidade) * representante"; answered in msdn: answer in msdn brasil


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -