The single quotes in SqlCommand were the problem.  I dropped them and
it worked fine.

Thanks everyone for your help!



On Jan 17, 8:02 am, akram mellice <[email protected]> wrote:
> the line sqlCmd = New SqlCommand("INSERT INTO tableName" _
>                                            + " (colDate, colCount)" _
>                                            + " VALUES ('@Date', 1)" _
>                                    , connSQL)
> replace with sqlCmd = New SqlCommand("INSERT INTO tableName" _
>                                            + " (colDate, colCount)" _
>                                            + " VALUES (@Date, 1)" _
>                                    , connSQL)
>
>
>
> On Mon, Jan 11, 2010 at 10: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
>
> --
> Akram Mellice

Reply via email to