Re: help with insert/updating date variables in table code included

Discussion in 'ASP .Net' started by Guest, Dec 14, 2003.

  1. Guest

    Guest Guest

    Part of the code as requested

    dim i as integer
    dim strSQL as string
    Public ConnectionString As String
    public cn As OleDbConnection

    public function IDXPREmpDetCreateInsert(byref TPREmpDet as SPREmpDet)

    strSQL ="INSERT INTO [PREmpDet] ( " & _
    "EmpCode," & _
    "Surname," & _
    "MartialStatus," & _
    "DOB," & _
    "WorksNo," & _
    "EmploymentStart," & _
    "EmploymentEnd," & _
    "PensionSchemeNo," & _
    ") VALUES (" & _
    "?,?,?,?,?,?,?,?)"

    cmdInsert= new OleDbCommand(strSQL,cn)
    with cmdInsert.Parameters
    Add("EmpCode", OleDbType.varchar , 5, "EmpCode")
    Add("Surname", OleDbType.varchar , 30, "Surname")
    Add("MartialStatus", OleDbType.varchar , 1, "MartialStatus")
    Add("DOB", OleDbType.date , 0, "DOB")
    Add("WorksNo", OleDbType.varchar , 10, "WorksNo")
    Add("EmploymentStart", OleDbType.date , 0, "EmploymentStart")
    Add("EmploymentEnd", OleDbType.date , 0, "EmploymentEnd")
    Add("PensionSchemeNo", OleDbType.integer , 0, "PensionSchemeNo")
    end with

    Dim i As In

    With cmdInsert

    .Parameters(0).Value = "AAAAA" Assigning Directly to see why the code fails
    .Parameters(1).Value = "SAYER"
    .Parameters(2).Value = "S"
    .Parameters(3).Value = #11/2/1931#
    .Parameters(4).Value = "1111"
    .Parameters(5).Value = #11/3/1962#
    .Parameters(6).Value = #1/3/1993#
    .Parameters(7).Value = 10

    End With

    cn.Open() 'already setup

    i = cmdInsert.ExecuteNonQuery() <- EXCEPTION OCCURS HERE WITH -> Invalid cast from Boolean to DateTime.

    cn.Close()
    Guest, Dec 14, 2003
    #1
    1. Advertising

  2. Cobra,
    I believe you need to use OleDbType.DBTimeStamp for your DateTime columns.
    http://www.able-consulting.com/ADODataTypeEnum.htm

    For more information, please see:
    http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDataOleDbOleDbTypeClassTopic.asp

    --

    Thanks,
    Carl Prothman
    Microsoft ASP.NET MVP
    http://www.able-consulting.com


    <> wrote
    > dim i as integer
    > dim strSQL as string
    > Public ConnectionString As String
    > public cn As OleDbConnection
    >
    > public function IDXPREmpDetCreateInsert(byref TPREmpDet as SPREmpDet)
    >
    > strSQL ="INSERT INTO [PREmpDet] ( " & _
    > "EmpCode," & _
    > "Surname," & _
    > "MartialStatus," & _
    > "DOB," & _
    > "WorksNo," & _
    > "EmploymentStart," & _
    > "EmploymentEnd," & _
    > "PensionSchemeNo," & _
    > ") VALUES (" & _
    > "?,?,?,?,?,?,?,?)"
    >
    > cmdInsert= new OleDbCommand(strSQL,cn)
    > with cmdInsert.Parameters
    > Add("EmpCode", OleDbType.varchar , 5, "EmpCode")
    > Add("Surname", OleDbType.varchar , 30, "Surname")
    > Add("MartialStatus", OleDbType.varchar , 1, "MartialStatus")
    > Add("DOB", OleDbType.date , 0, "DOB")
    > Add("WorksNo", OleDbType.varchar , 10, "WorksNo")
    > Add("EmploymentStart", OleDbType.date , 0, "EmploymentStart")
    > Add("EmploymentEnd", OleDbType.date , 0, "EmploymentEnd")
    > Add("PensionSchemeNo", OleDbType.integer , 0, "PensionSchemeNo")
    > end with
    >
    > Dim i As In
    >
    > With cmdInsert
    >
    > .Parameters(0).Value = "AAAAA" Assigning

    Directly to see why the code fails
    > .Parameters(1).Value = "SAYER"
    > .Parameters(2).Value = "S"
    > .Parameters(3).Value = #11/2/1931#
    > .Parameters(4).Value = "1111"
    > .Parameters(5).Value = #11/3/1962#
    > .Parameters(6).Value = #1/3/1993#
    > .Parameters(7).Value = 10
    >
    > End With
    >
    > cn.Open() 'already setup
    >
    > i = cmdInsert.ExecuteNonQuery() <- EXCEPTION OCCURS HERE WITH ->

    Invalid cast from Boolean to DateTime.
    >
    > cn.Close()
    >
    >
    >
    Carl Prothman [MVP], Dec 14, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,231
    Michael Borgwardt
    May 30, 2004
  2. dprichard
    Replies:
    0
    Views:
    449
    dprichard
    Aug 25, 2006
  3. news.rcn.com
    Replies:
    2
    Views:
    1,108
    Roedy Green
    Dec 10, 2007
  4. PT
    Replies:
    1
    Views:
    382
    Ken Schaefer
    Oct 7, 2004
  5. Sergio del Amo
    Replies:
    4
    Views:
    228
Loading...

Share This Page