Click here to Skip to main content
16,005,552 members
Home / Discussions / Database
   

Database

 
GeneralRe: A really stupid problem with SQL Pin
Carlos Antollini5-Apr-02 3:28
Carlos Antollini5-Apr-02 3:28 
GeneralRe: A really stupid problem with SQL Pin
Mazdak5-Apr-02 3:55
Mazdak5-Apr-02 3:55 
GeneralRe: A really stupid problem with SQL Pin
Carlos Antollini5-Apr-02 5:52
Carlos Antollini5-Apr-02 5:52 
GeneralRe: A really stupid problem with SQL Pin
Nick Parker5-Apr-02 7:06
protectorNick Parker5-Apr-02 7:06 
GeneralRe: A really stupid problem with SQL Pin
Dan Pomerchik7-Apr-02 6:42
Dan Pomerchik7-Apr-02 6:42 
GeneralRe: A really stupid problem with SQL Pin
Dan Pomerchik7-Apr-02 6:47
Dan Pomerchik7-Apr-02 6:47 
GeneralXP_SENDMAIL : HELP! Pin
1-Apr-02 10:26
suss1-Apr-02 10:26 
GeneralINSERT INTO problem - please!! Pin
Andrew Peace1-Apr-02 9:04
Andrew Peace1-Apr-02 9:04 
Hi,

Ok - first a plea! I NEED help with this - it's been driving me crazy and I know it's a really simple problem, but I've been too knocked out with this stupid code to spot it.

I have an Access database with several tables, including one named tblSchedule. It has seven fields, declared in this order:

ID - Autonumber
EmployeeID - Number
JobID - Number
Date - Date/time
AreaID - number
Description - text
Status - Number

You can download a database containing the exact schema for this table here.

OK, now, in VB I have the following code:
' Write a schedule entry to the database
'
' IN
' sched - the schedule entry
'
' OUT - success?
Public Function CreateScheduleEntry(sched As cScheduleEntry) As Boolean
On Error GoTo Error

    Dim adoConn As New ADODB.Connection
    Set adoConn = OpenDatabase
    
    adoConn.Execute "INSERT INTO tblSchedule " & sched.FormatSQL & ";"
    
    adoConn.Close

    CreateScheduleEntry = True
    Exit Function

Error:
    CreateScheduleEntry = False
    Exit Function
End Function


The schedule object looks like this:
Public ID As Integer
Public Employee As cEmployee
Public job As cJob
Public ScheduleDate As Date
Public Area As cArea
Public Description As String
Public Status As Integer

' Returns a SQL statement formatted for an INSERT INTO statement,
' of formtat ({fields}) VALUES ({values})
'
' IN
' OUT - SQL string as described above
Public Function FormatSQL() As String
    FormatSQL = "(" & _
                "EmployeeID,JobID,Date,AreaID,Description,Status" & _
                ") VALUES (" & _
                Employee.ID & "," & _
                job.ID & "," & _
                "#" & Month(Date) & "/" & Day(Date) & "/" & Year(Date) & "#," & _
                Area.ID & "," & _
                QuoteString(Description) & "," & _
                Status & _
                ")"
End Function
The INSERT INTO fails EVERY time. So I thought, well, if I can't get it to work this way, how about executing a basic INSERT INTO statement against the table. But that doesn't work either:
INSERT INTO tblSchedule (EmployeeID,JobID,Date,AreaID,
Description,Status) VALUES (1,2,#4/1/2002#,4,'test',1)
Any help on this will be really really really really really appreciated. I just know it's gonna be a stupid, simple, problem, but at the minute I'm too blind to see it.

The QuoteString function just double quotes a string so that apostraphes don't mess up the SQL statement. This exact code, with changed field names, is used on another table and works fine.

Thanks!

--
Andrew.
GeneralRe: INSERT INTO problem - please!! Pin
1-Apr-02 9:30
suss1-Apr-02 9:30 
GeneralRe: INSERT INTO problem - please!! Pin
Andrew Peace1-Apr-02 10:06
Andrew Peace1-Apr-02 10:06 
GeneralRe: INSERT INTO problem - please!! Pin
Bruce Duncan2-Apr-02 8:40
Bruce Duncan2-Apr-02 8:40 
GeneralWriting Stored Procedures Pin
Michael P Butler1-Apr-02 1:19
Michael P Butler1-Apr-02 1:19 
GeneralRe: Writing Stored Procedures Pin
Mazdak1-Apr-02 1:32
Mazdak1-Apr-02 1:32 
GeneralRe: Writing Stored Procedures Pin
Michael P Butler1-Apr-02 1:41
Michael P Butler1-Apr-02 1:41 
GeneralRe: Writing Stored Procedures Pin
Mazdak1-Apr-02 4:39
Mazdak1-Apr-02 4:39 
GeneralRe: Writing Stored Procedures Pin
AndyG1-Apr-02 4:34
AndyG1-Apr-02 4:34 
GeneralRe: Writing Stored Procedures Pin
Michael P Butler1-Apr-02 8:46
Michael P Butler1-Apr-02 8:46 
GeneralADO problem Pin
milan31-Mar-02 17:44
milan31-Mar-02 17:44 
GeneralRe: ADO problem Pin
Wanderley M1-Apr-02 3:16
Wanderley M1-Apr-02 3:16 
GeneralMSDE users and passwords Pin
Lockhart31-Mar-02 9:47
Lockhart31-Mar-02 9:47 
GeneralRe: MSDE users and passwords Pin
Giles31-Mar-02 10:05
Giles31-Mar-02 10:05 
GeneralRe: MSDE users and passwords Pin
Lockhart31-Mar-02 22:45
Lockhart31-Mar-02 22:45 
GeneralRe: MSDE users and passwords Pin
David Salter3-Apr-02 11:17
David Salter3-Apr-02 11:17 
Generalabout document_storing in SQL SERVER2K Pin
30-Mar-02 16:26
suss30-Mar-02 16:26 
QuestionHow can I get a list of databases in .NET? Pin
spbdenis29-Mar-02 3:03
spbdenis29-Mar-02 3:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.