Use convert.todatetime()

On Mon, Jan 11, 2010 at 2:56 PM, jtaylor <[email protected]> wrote:

> I'm trying to insert a row into a SQL Server table but I keep getting
> a "Conversion failed when converting character string to smalldatetime
> data type." error.
>
> This code works:
>            sqlCmd = New SqlCommand("INSERT INTO tableName" _
>                                            + " (colDate, colCount)" _
>                                            + " VALUES ('1/9/2010
> 12:00:00 AM', 1)" _
>                                    , connSQL)
>            sqlCmd.ExecuteNonQuery()
>
> While this does not:
>            sqlCmd = New SqlCommand("INSERT INTO tableName" _
>                                            + " (colDate, colCount)" _
>                                            + " VALUES ('@Date', 1)" _
>                                    , connSQL)
>            sqlCmd.Parameters.Clear()
>            sqlCmd.Parameters.AddWithValue("@Date", "1/9/2010 12:00:00
> AM")
>            sqlCmd.ExecuteNonQuery()
>
> What am I overlooking?
>
> VB.NET & VS2005
>



-- 
Hozefa Unwala

Reply via email to