Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Re: help with insert/updating date variables in table code included

Reply
Thread Tools

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

 
 
Guest
Posts: n/a
 
      12-14-2003




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()



 
Reply With Quote
 
 
 
 
Carl Prothman [MVP]
Guest
Posts: n/a
 
      12-14-2003
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...ClassTopic.asp

--

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


<(E-Mail Removed)> 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()
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Last compilation date included in .class Nomak Java 2 04-19-2005 08:19 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Given a date, how to find the beginning date and ending date of that week Matt ASP .Net 1 11-08-2003 09:14 PM
Given a date, how to find the beginning date and ending date of that week Matt C Programming 3 11-08-2003 09:07 PM
Given a date, how to find the beginning date and ending date of that week Matt C++ 2 11-08-2003 08:30 PM



Advertisments