Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old July 31st, 2006, 04:37 AM
Enzo Enzo is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Location: HK
Posts: 178 Enzo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 15 h 43 m 26 sec
Reputation Power: 4
Storing the data into database

Code:
Public cn As Connection
Public rsStationInfo As Recordset
Public rsWQSampleData As Recordset
Public rsDepthCode As Recordset
Public rsTideLevel As Recordset
Public rsTideCycle As Recordset
Public rsSeason As Recordset

Private Sub CmdConvert_Click()
On Err GoTo Errhandler
nInFile = 1
'If Len(Pathtxt.Text) = 0 Then
'    MsgBox "Please select the summary file"
'    Exit Sub
'ElseIf Len(DBPathtxt.Text) = 0 Then
'    MsgBox "Please select the database file"
'    Exit Sub
'End If
Close #NumFile
    ReDim Preserve InFile(1) As String
    InFile(0) = Pathtxt.Text
    For fNo = 0 To nInFile - 1 ' for each input summary file (.sum)
        Open InFile(fNo) For Input As #NumFile
            'If Not EOF(NumFile) Then ' read data from .sum file till EOF
                        Line Input #NumFile, ContractHead ' read a line of data
                        Line Input #NumFile, JobHead
                        
                        Line Input #NumFile, s1
                        
                        s2 = "" & ParseString(data(), s1, ",") ' extract data fields divided by comma
                        VesselHead = data(0)
                        Vessel = data(1)
                        WeatherHead = data(2)
                        Weather1 = data(3)
                        SeaConHead = data(4)
                        SeaCon = data(5)
                        TideHead = data(6)
                        Tide = data(7)
                        WindDirHead = data(8)
                        WindDir = data(9)
                        Line Input #NumFile, s3
                        Line Input #NumFile, s3

             Do While Not EOF(NumFile) ' read data from .sum file till EOF
                        Line Input #NumFile, s4
                            If Left$(s4$, 11) = "Head_Vessel" Then
                                Line Input #NumFile, s4
                                Line Input #NumFile, s4
                                Line Input #NumFile, s4
                            End If
                        Text1.Text = "" & s4
                        s4 = "" & ParseString(WQInfo(), s4, ",") ' extract data fields divided by comma
                        StationName = Trim(WQInfo(0))
                        Time = WQInfo(1)
                        Easting = Trim(WQInfo(2))
                        Northing = Trim(WQInfo(3))
                        Depth = Trim(WQInfo(4))
                        Temperature = Trim(WQInfo(5))
                        Salinity = Trim(WQInfo(6))
                        DOPercent = Trim(WQInfo(8))
                        DOMgl = Trim(WQInfo(9))
                        Turbidity = Trim(WQInfo(10))
                        pH = Trim(WQInfo(11))
                        Depth1 = Trim(WQInfo(14))
                        Temperature1 = Trim(WQInfo(15))
                        Salinity1 = Trim(WQInfo(16))
                        DOPercent1 = Trim(WQInfo(18))
                        DOMgl1 = Trim(WQInfo(19))
                        Turbidity1 = Trim(WQInfo(20))
                        pH1 = Trim(WQInfo(11))
                        Date = WQInfo(21)
                        SeasonID = 1
                        TideLevelID = 1
                        TideCycleID = 1
                        WaterDepth = 30
                        Weather = "Sunny"
                        Observation = "test"
                        remarks = "test"
                        Call FileCopy(App.Path & "\DataSource\WQData.mdb", DBFname)
                        Call OpenDB(DBFname)
                        Call AddRecord(StationName, Date, SeasonID, TideCycleID, TideLevelID, Weather, WaterDepth, Observation, remarks, Time, Easting, Northing, _
                        Depth, Temperature, Salinity, DOPercent, DOMgl, Turbidity, pH, Depth1, Temperature1, Salinity1, DOPercent1, DOMgl1, Turbidity1, pH1)
             Loop
             'End If
        Close #NumFile
        Call CloseDB
    Next
Errhandler:
End Sub

Function AddRecord(StationName, SurveyDate, SeasonID, TideCycleID, TideLevelID, Weather, WaterDepth, Observation, remarks, Time, _
Easting, Northing, DepthCoDepth, Temperature, Salinity, DOPercent, DOMgl, Turbidity, pH, Depth1, Temperature1, Salinity1, DOPercent1, DOMgl1, Turbidity1, pH1)

If cn.State = adStateOpen Then
    
    cn.Execute "Insert into WQSampleData(SampleID, StationID, Time, Easting,Northing,Depth, Temperature, Salinity, DOPercent, DOMgl, Turbidity, pH, Depth1, Temperature1, Salinity1, DOPercent1, DOMgl1, Turbidity1, pH1 ) " & _
                        "VALUES (' ',' ','Time', 'Easting','Northing','Depth', 'Temperature', 'Salinity', 'DOPercent', 'DOMgl', 'Turbidity', 'pH', 'Depth1', 'Temperature1', 'Salinity1', 'DOPercent1', 'DOMgl1', 'Turbidity1', 'pH1' );"
    End If

End Function


The Sample ID and Station ID are the auto number
However, i can't add the data into the DB
And it said "Syntax error on insert statement"
What wrong with that?

Reply With Quote
  #2  
Old August 1st, 2006, 08:20 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,932 sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 6 Days 22 h 36 m 35 sec
Reputation Power: 1243
Enzo,

The best thing to do is to write the SQL string out to a Label on your form and cut and paste it into your DB package and try and run it. This will give you an idea of the problem.

Without having time to trawl through all your code I think your problems lie in the Function AddRecord:

Firstly, be careful what you name the parameters because Time is a reserved word.

Secondly, check what you have declared the fields as in the database because I dont think you should have single quotes around numeric data.

Finally, I believe the main cause of your problem is that you are inserting the names of the variables into the DB and not the values. I may be wrong but I think you need to break up the string using '" & variablename & "', try something like this:
Code:
Function AddRecord(StationName, SurveyDate, SeasonID, TideCycleID, TideLevelID, Weather, WaterDepth, Observation, remarks, varTime, _
Easting, Northing, DepthCoDepth, Temperature, Salinity, DOPercent, DOMgl, Turbidity, pH, Depth1, Temperature1, Salinity1, DOPercent1, DOMgl1, Turbidity1, pH1)

If cn.State = adStateOpen Then
    
    cn.Execute "Insert into WQSampleData(SampleID, StationID, Time, Easting,Northing,Depth, Temperature, Salinity, DOPercent, DOMgl, Turbidity, pH, Depth1, Temperature1, Salinity1, DOPercent1, DOMgl1, Turbidity1, pH1 ) " & _
                        "VALUES (' ',' ','" &  varTime & "', '" & Easting & "','" & Northing & "','" & Depth & "', '" & Temperature & "', '" & Salinity & "', '" & DOPercent & "', '" & DOMgl & "', '" & Turbidity & "', '" & pH & "', '" & Depth1 & "', '" & Temperature1 & "', '" & Salinity1 & "', '" & DOPercent1 & "', '" & DOMgl1 & "', '" & Turbidity1 & "', '" & pH1 &"' );"
    End If

End Function

Like I say, I dont know what data types your fields are defined as, if they are numeric you will have to remove the single quotes:
eg. , " & pH & ",

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Storing the data into database


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT