problem with a date parameter in ASP.Net

  • Thread starter Thread starter Elmo Watson
  • Start date Start date
E

Elmo Watson

The date format in the 'weekending' textbox is 5/5/2007
Here's what I've got:


With cmd.Parameters
..Add(New SqlParameter("@SQLweekending", SqlDbType.DateTime,
weekending.Text))
the error message is:
"Conversion from string "4/8/2007" to type 'Integer' is not valid."
Then, I tried:
..Add(New SqlParameter("@SQLweekending", SqlDbType.DateTime,
CDate(weekending.Text)))

but, before I even tried it, it gave me a blue squiggly line, with an error
message:
"Error 2 Value of type 'Date' cannot be converted to 'Integer'"

How can I get this to work?
 
You are not using the constructor properly. You are attempting to pass the
value of weekending.Text to a parameter of type Int. The third parameter is
not the value parameter. It is the length parameter for the datatype. In the
case of a datetime, that should be 4 I believe. Add a 4 for the third
parameter as such:

..Add(New SqlParameter("@SQLweekending", SqlDbType.DateTime,
4,CDate(weekending.Text)))

and see what happens.
 
Back
Top