I'm wondering if I should use const string when using code like this:
public DataTable GetSomeData(int id)
{
var con = new SqlConnection(ConnString);
const string sql = "SELECT * FROM [data] WHERE [id]=@id";
var cmd = new SqlCommand(sql, con);
cmd.Parameters.AddWithValue("@id", id);
var dt = new DataTable();
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
dt.Load(dr);
con.Close();
return dt;
}
ReSharper suggested I solved it this way, but I'm told I shouldn't because it's not really constant. It changes when the parameters are added. I thought this way was proper because it's constant on the server running the code and only changes when it reaches the database.
So, what is the best way to do this?
sqldoesn't...