Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 17974
Number of posts: 55343

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
executing insert statements to a database Posted by Dana Roy on 10 Sept 2004 at 3:27 AM
I've used this code, but it doesn't seem to updating my database. Does anyone have any suggestions??


Dim bAgencyStaff As Integer
Dim ssql As String

ssql = "insert into casual_staff_used (date_booked, casual_staff_code, agency_staff, hours_worked, per_hour) values (" & dtBookingDate & "," & cboStaffName.ItemData(cboStaffName.ListIndex) & "," & bAgencyStaff & "," & txtHours.Text & "," & txtRate.Text & ")"

If optAgency = True Then
bAgencyStaff = 0
Else
bAgencyStaff = 1
End If

adoCN.Open
adoCN.BeginTrans
adoCN.Execute ssql
adoCN.CommitTrans
adoCN.Close

Unload Me
End Sub
Report
Re: executing insert statements to a database Posted by Flakes on 10 Sept 2004 at 3:31 AM
This message was edited by Flakes at 2004-9-10 3:31:24

: I've used this code, but it doesn't seem to updating my database. Does anyone have any suggestions??
:
:
: Dim bAgencyStaff As Integer
: Dim ssql As String
:
: ssql = "insert into casual_staff_used (date_booked, casual_staff_code, agency_staff, hours_worked, per_hour) values (" & dtBookingDate & "," & cboStaffName.ItemData(cboStaffName.ListIndex) & "," & bAgencyStaff & "," & txtHours.Text & "," & txtRate.Text & ")"
here
If optAgency = True Then
: bAgencyStaff = 0
: Else
: bAgencyStaff = 1
: End If
:
: adoCN.Open
: adoCN.BeginTrans
: adoCN.Execute ssql
: adoCN.CommitTrans
: adoCN.Close
:
: Unload Me
: End Sub
:


What do you see when you put a
debug.print ssql
or a
msgbox ssql

where i have marked in red?


Report
Re: executing insert statements to a database Posted by Genjuro on 10 Sept 2004 at 3:36 AM
: This message was edited by Flakes at 2004-9-10 3:31:24

: : I've used this code, but it doesn't seem to updating my database. Does anyone have any suggestions??
: :
: :
: : Dim bAgencyStaff As Integer
: : Dim ssql As String
: :
: : ssql = "insert into casual_staff_used (date_booked, casual_staff_code, agency_staff, hours_worked, per_hour) values (" & dtBookingDate & "," & cboStaffName.ItemData(cboStaffName.ListIndex) & "," & bAgencyStaff & "," & txtHours.Text & "," & txtRate.Text & ")"
: here
: If optAgency = True Then
: : bAgencyStaff = 0
: : Else
: : bAgencyStaff = 1
: : End If
: :
: : adoCN.Open
: : adoCN.BeginTrans
: : adoCN.Execute ssql
: : adoCN.CommitTrans
: : adoCN.Close
: :
: : Unload Me
: : End Sub
: :
:
:
: What do you see when you put a
: debug.print ssql
: or a
: msgbox ssql
:
: where i have marked in red?

Also, check whether such an INSERT query works - perhaps the database returns a SQL error, which you don't get because it isn't a VB error but still causes the query to fail.
Report
Re: executing insert statements to a database Posted by Dana Roy on 10 Sept 2004 at 4:29 AM
: This message was edited by Flakes at 2004-9-10 3:31:24

: : I've used this code, but it doesn't seem to updating my database. Does anyone have any suggestions??
: :
: :
: : Dim bAgencyStaff As Integer
: : Dim ssql As String
: :
: : ssql = "insert into casual_staff_used (date_booked, casual_staff_code, agency_staff, hours_worked, per_hour) values (" & dtBookingDate & "," & cboStaffName.ItemData(cboStaffName.ListIndex) & "," & bAgencyStaff & "," & txtHours.Text & "," & txtRate.Text & ")"
: here
: If optAgency = True Then
: : bAgencyStaff = 0
: : Else
: : bAgencyStaff = 1
: : End If
: :
: : adoCN.Open
: : adoCN.BeginTrans
: : adoCN.Execute ssql
: : adoCN.CommitTrans
: : adoCN.Close
: :
: : Unload Me
: : End Sub
: :
:
:
: What do you see when you put a
: debug.print ssql
: or a
: msgbox ssql
:
: where i have marked in red?
:
: it prints out the query correctly but it says something about date not being able to be added as a value for date_booked column


insert into casual_staff_used (date_booked, casual_staff_code, agency_staff, hours_worked, per_hour) values (10/09/2004,13,0,7,7)
:

Report
Re: executing insert statements to a database Posted by Flakes on 10 Sept 2004 at 4:41 AM
: : This message was edited by Flakes at 2004-9-10 3:31:24

: : : I've used this code, but it doesn't seem to updating my database. Does anyone have any suggestions??
: : :
: : :
: : : Dim bAgencyStaff As Integer
: : : Dim ssql As String
: : :
: : : ssql = "insert into casual_staff_used (date_booked, casual_staff_code, agency_staff, hours_worked, per_hour) values (" & dtBookingDate & "," & cboStaffName.ItemData(cboStaffName.ListIndex) & "," & bAgencyStaff & "," & txtHours.Text & "," & txtRate.Text & ")"
: : here
: : If optAgency = True Then
: : : bAgencyStaff = 0
: : : Else
: : : bAgencyStaff = 1
: : : End If
: : :
: : : adoCN.Open
: : : adoCN.BeginTrans
: : : adoCN.Execute ssql
: : : adoCN.CommitTrans
: : : adoCN.Close
: : :
: : : Unload Me
: : : End Sub
: : :
: :
: :
: : What do you see when you put a
: : debug.print ssql
: : or a
: : msgbox ssql
: :
: : where i have marked in red?
: :
: : it prints out the query correctly but it says something about date not being able to be added as a value for date_booked column
:
:
: insert into casual_staff_used (date_booked, casual_staff_code, agency_staff, hours_worked, per_hour) values (10/09/2004,13,0,7,7)
: :
:
:

try this
ssql = "insert into casual_staff_used (date_booked, casual_staff_code, agency_staff, hours_worked, per_hour) values ('" & dtBookingDate & "'," & cboStaffName.ItemData(cboStaffName.ListIndex) & "," & bAgencyStaff & "," & txtHours.Text & "," & txtRate.Text & ")"


I just added the single quotes around the date value



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.