0

This is a strange one to me.

The signature of the Add parameter method requires a SqlType but when I use that

//Create and open a connection to SQL Server 
SqlConnection connection = new SqlConnection(DatabaseHelper.ConnectionString);
connection.Open();

//Create a Command object
SqlCommand command = new SqlCommand( "stpInsertFile", connection);
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Parameters.Add("@LastMod", System.Data.SqlTypes.SqlDateTime);

it shows this error:

'System.Data.SqlTypes.SqlDateTime' is a 'type', which is not valid in the given context

3 Answers 3

3

You should be using the SqlDbType enumeration, not SqlTypes so, something like:

command.Parameters.Add("@LastMod", SqlDbType.DateTime);
Sign up to request clarification or add additional context in comments.

Comments

3

You're adding a SqlType (which is just a type) but the Add method expects a SqlDbType (which is an enum):

command.Parameters.Add("@LastMod", System.Data.SqlDbType.DateTime);

1 Comment

Ok thanks for the explanation. I think I was staring at the screen too long!
1

The signature you're looking at is Add(string,SqlDbType),that isn't SqlType. You're using the wrong type there. You should be using SqlDbType

Or as Christos mentioned, you can give it the value and have it figure things out.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.