I am building a website using mvc and want to save some data using a stored procedure that contains a set of parameters. I was wondering if it's possible to set some of those parameters as optional. The reason being that the data that gets sent back depends on a type of account. If the user edits account type 1, then all parameters must be sent back, if they edit account type 2, then only 3 parameters get sent back.
sql parameters:
alter PROCEDURE web.Maint_UpdateClinic
@AccountID INT
,@IsActive BIT = 1
,@AccountName VARCHAR(100) = NULL
,@AccountAddress VARCHAR(100) = NULL
,@City VARCHAR(100) = NULL
,@State VARCHAR(2) = NULL
,@ZipCode VARCHAR(10) = NULL
,@PhoneNumber VARCHAR(20) = NULL
,@WebID INT
action in controller calling the procedure:
using (OdbcConnection _conn = new OdbcConnection("FILEDSN=c:\\datasources\\RxCard.dsn"))
using (OdbcCommand cmd1 = new OdbcCommand())
{
cmd1.Connection = _conn;
cmd1.CommandText = "{call web.Maint_UpdateClinic(?,?,?,?,?,?,?,?,?)}";
cmd1.Parameters.AddWithValue("@AccountID", AccountID);
cmd1.Parameters.AddWithValue("@IsActive", true);
cmd1.Parameters.AddWithValue("@AccountName", AccountName);
cmd1.Parameters.AddWithValue("@Address", Address);
cmd1.Parameters.AddWithValue("@City", City);
cmd1.Parameters.AddWithValue("@State", State);
cmd1.Parameters.AddWithValue("@ZipCode", ZipCode);
cmd1.Parameters.AddWithValue("@PhoneNumber", PhoneNumber);
cmd1.Parameters.AddWithValue("@WebID", CookieStore.GetCookie("WebId"));
cmd1.CommandType = CommandType.StoredProcedure;
_conn.Open();
cmd1.ExecuteNonQuery();
_conn.Close();
}