Error converting data type nvarchar to datetime - Please help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Baker

    Error converting data type nvarchar to datetime - Please help

    this seems to be an SQL Server error but I cant work out how it is occuring.
    Itr is also after 3am and I cant keep working but need to demo by tomorrow.
    TIA. The code is:
    Private Sub myMethod(ByVal cust As String, ByVal invDate As Date)
    [snip]
    Dim paramDate As New OleDb.OleDbPara meter, Dim paramCustomer As New
    OleDb.OleDbPara meter
    [snip]
    paramDate.Param eterName = "@InvDate"
    paramDate.Value = invDate
    paramDate.OleDb Type = OleDb.OleDbType .Date
    cmdSQL.Paramete rs.Add(paramDat e)

    paramCustomer.P arameterName = "@code"
    paramCustomer.V alue = cust
    cmdSQL.Paramete rs.Add(paramCus tomer)

    myOleDbDataAdap ter.Fill(DTResu lt) ******* exception thrown - "Error
    converting data type nvarchar to datetime"
    ....

    Stored proc being called is:
    CREATE PROCEDURE dbo.bo_GetDisti nctOrders (@code as nvarchar(8), @invdate as
    datetime) AS
    SELECT prodcode, qty, price, comment
    FROM Orders
    where custcode = @code and InvDate = @InvDate

    GO (Note, InvDate in the Orders table is a datetime:-)


  • Robin Tucker

    #2
    Re: Error converting data type nvarchar to datetime - Please help

    It isn't for me to help you with your homework/coursework, but consider
    this: you must add the parameters to your cmdSQL.Paramete rs in the order in
    which SQL server requires them to be passed in (in your case char then
    date).

    "Andrew Baker" <no@spam.com> wrote in message
    news:eW4GbiFYEH A.2364@TK2MSFTN GP12.phx.gbl...[color=blue]
    > this seems to be an SQL Server error but I cant work out how it is[/color]
    occuring.[color=blue]
    > Itr is also after 3am and I cant keep working but need to demo by[/color]
    tomorrow.[color=blue]
    > TIA. The code is:
    > Private Sub myMethod(ByVal cust As String, ByVal invDate As Date)
    > [snip]
    > Dim paramDate As New OleDb.OleDbPara meter, Dim paramCustomer As[/color]
    New[color=blue]
    > OleDb.OleDbPara meter
    > [snip]
    > paramDate.Param eterName = "@InvDate"
    > paramDate.Value = invDate
    > paramDate.OleDb Type = OleDb.OleDbType .Date
    > cmdSQL.Paramete rs.Add(paramDat e)
    >
    > paramCustomer.P arameterName = "@code"
    > paramCustomer.V alue = cust
    > cmdSQL.Paramete rs.Add(paramCus tomer)
    >
    > myOleDbDataAdap ter.Fill(DTResu lt) ******* exception thrown - "Error
    > converting data type nvarchar to datetime"
    > ...
    >
    > Stored proc being called is:
    > CREATE PROCEDURE dbo.bo_GetDisti nctOrders (@code as nvarchar(8), @invdate[/color]
    as[color=blue]
    > datetime) AS
    > SELECT prodcode, qty, price, comment
    > FROM Orders
    > where custcode = @code and InvDate = @InvDate
    >
    > GO (Note, InvDate in the Orders table is a datetime:-)
    >
    >[/color]


    Comment

    Working...