I tried this
sqlCmd.Parameters.AddWithValue("@Date", New DateTime(1,9,2010))
but it gave me a "Year, Month, and Day parameters describe an un-
representable DateTime". I changed it to be Year, Month, Day, and
then I was back to the conversion error on the .ExecuteNonQuery().
On Jan 13, 5:36 am, Jamie Fraser <[email protected]> wrote:
> This line
>
> sqlCmd.Parameters.AddWithValue("@Date", "1/9/2010 12:00:00
> AM")
>
> Adds your parameter as a type string (which gets converted to a varchar by
> SQL)
>
> Try changing it to
>
> sqlCmd.Parameters.AddWithValue("@Date", New DateTime(1,9,2010))
>
> Or something similar.
>
> On Mon, Jan 11, 2010 at 8: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