I'm assigning objects to this list of SqlParameter and then trying to execute the SqlCommand, but it throws an exception saying that one of the objects could not be converted into SqlDbType. Preferably I want to handle such objects before adding them to the parameter collection list. So, how would I check whether a value being added to parameter list is a good/proper one or not? What property should I check for?
Here's is my code :
bool Submit(Progs progs, CommandType commandType, string commandText)
{
try
{
List<SqlParameter> paramCollection = new List<SqlParameter>();
foreach(Prog p in progs)
{
SqlParameter spTemp = new SqlParameter { ParameterName = p.Name , Value = p.Value};
paramCollection.Add(spTemp);
using (SqlConnection con = GetConnection())
{
SqlCommand cmd = new SqlCommand { CommandType = commandType, CommandText = commandText, Connection = con };
con.Open();
cmd.Parameters.AddRange(paramCollection ); // Exception is thrown from this line
cmd.ExecuteNonQuery();
}
return true;
}
catch(Exception exc)
{
return false;
}
}
The exception thown says : No mapping exists from object type sol2.CodeBase.BL.Letter[] to a known managed provider native type.
PS : There is a property for of SqlParameter called ParamaterIsSqlType(yes, it's paramAter and not paramEter), which appears only during runtime(i.e. when I inspect spTemp with a breakpoint on the next line) and which is always set to false? What kind of property is this, so that it appears only during runtime??? Also, what value this "ParamaterIsSqlType" indicates?