-2

Well, Im curious what will happen if i pass some parameters without @ symbol

public static int Run(string command,string anotherParameter, DataTable dt)
 {
   SqlDataAdapter adapter = new SqlDataAdapter("SPName", Connection.Connect);
   adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
   adapter.SelectCommand.Parameters.Add("@command",SqlDbType.NVarChar).Value=command;

   //another one without @        
   adapter.SelectCommand.Parameters.Add("anotherParameter",SqlDbType.NVarChar).Value=anotherParameter;
     try
        {

            return adapter.Fill(dt);
        }
     catch (Exception ex)
        {
            return -1;
        }
        finally
        {
            adapter.Dispose();
        }     

 }

this may run sometimes and failed another?

Thanks

dotmido
  • 1,374
  • 3
  • 13
  • 29

1 Answers1

1

If you don't add "@" before parameter name, the "@" is added automatically.But good practice is to manually add @ and do not rely on automatic functionality. See http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparameter.parametername.aspx for more information

Veer
  • 1,575
  • 3
  • 16
  • 40