I'm trying to add parameters to SqlCommand, but it inserts parameter names instead of parameter values.
This is the code snippet:
var QueryString1 = "Insert into UsersTable (Username, Password, IsAdmin, Email, Budget, Phone) " +
"values ('@Un', '@P','" + user.IsAdmin + "', '@E', '@B', '@Ph')";
using (SqlCommand command = new SqlCommand(QueryString1, con))
{
command.Parameters.Add("@Un", SqlDbType.Text);
command.Parameters["@Un"].Value = user.UserName;
command.Parameters.Add("@P", SqlDbType.Text);
command.Parameters["@P"].Value = user.Password;
command.Parameters.Add("@E", SqlDbType.Text);
command.Parameters["@E"].Value = user.Email;
command.Parameters.Add("@B", SqlDbType.Text);
command.Parameters["@B"].Value = user.Budget.Amount + "-" + user.Budget.Currency;
command.Parameters.Add("@Ph", SqlDbType.VarChar);
command.Parameters["@Ph"].Value = user.Phone;
if (command.ExecuteNonQuery().Equals(0))
{
con.Close();
return InternalServerError();
}
con.Close();
return Ok();
}
sorry for blurred records :)

user.IsAdminis still being inlined instead of sent as a parameter.TEXTdata type is obsolete and should be replaced byVARCHAR(MAX)and on your last parameter, always specify the length of varchar parameters.