write sql command to text file
I want to write sql command to text file with parameter values. Following
is my code for replacing parameter with appropriate values.
string commandText = commandInfo.CommandText;
if (commandInfo.Parameters.Count > 0)
{
foreach (SqlParameter parameter in commandInfo.Parameters)
{
commandText=commandText.Replace(parameter.ParameterName,parameter.Value==(object)DBNull.Value?(object)DBNull.Value:("'"+parameter.Value.ToString()+"'"));
}
}
the catch is although all other parameter values are replaced
correctly.those having null values are taken up as blank i.e
'parameter1',,'param2'
between the two is the null valued parameter in final string.
What can be the alternative?
No comments:
Post a Comment