I am trying to generate a value first and then I try to pass that value into SQL query but my query returns null. I tried debugging my code I have value inside myvalue variable.
I am not sure it can be done the way I am doing. Can pass I the value like below? if not any suggestions, please.
public ActionResult Index(View model)
{
using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["DB_MYTABLE_CONNECTION_STRING"].ConnectionString))
{
var myvalue = MyUtil.GenerateKey(model.Name, model.phonenumber);
con.Open();
string query = "select count(*) from customer where key = @myvalue";
using (var cmd = new SqlCommand(query, con))
{
int rowsAmount = (int)cmd.ExecuteScalar();
}
}
}
cmd.Parameters.Add()