I give up with this. Need help

G

Guest

Hi,
I have a table with a field that should store date and time. The table
column data type is datetime.

I am trying

Dim dt as datetime

helper.exeutenonquery(connection,storedprocedure,"testproc",new
sqlparameter("@date",dbtype.datetime,dt.now.tostring()))

I get the error

"Cast form string "11/1/2005 10:43:24 AM" to typr integer is not valid.

Please. What's the recommended way in passing date or datetime to sql server
and waht is the recommended column datatype in sql server. So far I believe
datetime is recommended for sql server but waht if I need to store the date
as 20051101?

Please assist.
 
R

Russell B. Eggen

I think you will find that these columns are really stored as strings.
I believe you need to convert to an integer type before you can use it
as you've defined it.

I use groups to define the numerics and then use them that way.

HTH,
 
C

Chris Dunaway

Chris said:
Hi,
I have a table with a field that should store date and time. The table
column data type is datetime.

Then why are you converting it to a string when you pass it in?
Dim dt as datetime

helper.exeutenonquery(connection,storedprocedure,"testproc",new
sqlparameter("@date",dbtype.datetime,dt.now.tostring()))

Here, you call the "tostring" method so you are passing in a string and
not a datetime. Secondly, "Now" is a shared method of the DateTime
class. You should not call it on an instance of the class. VB allows
this, C# does not. Have you tried this:

helper.exeutenonquery(connection,storedprocedure,"testproc",new
sqlparameter("@date",dbtype.datetime,DateTime.Now))

-- OR (using your variable) --

Dim dt as datetime

dt = DateTime.Now

helper.exeutenonquery(connection,storedprocedure,"testproc",new
sqlparameter("@date",dbtype.datetime, dt))
 

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