Problem:
- Stored procedure input parameters data type specific (SqlDbType.Int,
SqlDbType.VarChar,etc).
- Form submitted value in TextBox, DropDownList, etc are all string
type (I guess). Some maybe empty.
I need a function that would grab the string value and dynamically
convert to the corresponding data type specific sql parameter OR
DBNull.Value. The problem is that I have to specifically specify what
data type the function will return. I don't want to do an if for every
single parameter ..
if(DateEnd.Value != "") {
myCommand.Parameters.Add("@strDateEnd",
SqlDbType.VarChar).Value =
Convert.ToDateTime(DateEnd.Value); ;
}
else {
myCommand.Parameters.Add("@strDateEnd",
SqlDbType.VarChar).Value = DBNull.Value;
}