The parameter data type of Char is invalid.

C

craigkenisston

I have a generic routine that I create for quick call to SqlServer
stored procedures :

public int ExecuteStoredNonQuery(string StoredName, string[]
ParamNames, object[] Directions, object[] Values)
{
SqlConnection myConnection = new SqlConnection(ConnectionString);
SqlCommand myCommand = new SqlCommand();
SqlDataAdapter adapter = new SqlDataAdapter(myCommand);

myCommand.Connection = myConnection;
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandText = StoredName;

int Count = ParamNames.Length;

for (int i=0; i<Count; i++)
{
SqlParameter param = new SqlParameter("@"+ParamNames, Values);
param.Direction = (ParameterDirection)Directions;
myCommand.Parameters.Add(param);
}

myConnection.Open();
int rowCount = myCommand.ExecuteNonQuery();
myConnection.Close();

return rowCount;
}


This has been working perfect with everything, until I dealt with a
stored procedure with parameters of type Char(1).
I send the SqlServer's Char(1) parametes as the System.Char type. So, I
gues I'd be fine there, however I get the error on the subject "The
parameter data type of Char is invalid".
Why ?
What's special on Char here different of Varchar which has been used
before ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top