Hi,
I had this code working to import one column in a table as a starter point, but now that i'm trying to import all the columns in the table, i'm running into problems.
When I run the app, I get this Microsoft . NET Framework error:
Syntax error in INSERT INTO statement
I've tried just about every combination I can think of for the sql statement and still the same error message.
Can anyone help me identify my error? - Imports System.IO
-
Imports System.Data.OleDb
-
Public Class Update2
-
Sub LoadData()
-
Dim objStreamReader As StreamReader = File.OpenText("/CMgmt/import.csv")
-
While objStreamReader.Peek() <> -1
-
Dim Str1() As String = Split(objStreamReader.ReadLine(), ",")
-
AddRecord(Str1(0), Str1(1), Str1(2), Str1(3), Str1(4), Str1(5), Str1(6))
-
End While
-
objStreamReader.Close()
-
End Sub
-
Sub AddRecord(ByVal first As String, ByVal last As String, ByVal address As String, ByVal postal As String, ByVal city As String, ByVal prov As String, ByVal tel As String)
-
Dim objConnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=/CMgmt/CMgmt.mdb")
-
objConnection.Open()
-
Dim SQL As String = "INSERT INTO [Import_T](first,last,address,postal,city,prov,tel) VALUES ('" & first & "','" & last & "','" & address & "','" & postal & "','" & city & "','" & prov & "','" & tel & "')"
-
Dim objCommand As OleDbCommand
-
objCommand = New OleDbCommand(SQL, objConnection)
-
objCommand.ExecuteNonQuery()
-
objConnection.Close()
-
End Sub
-
-
Private Sub Update2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
Me.LoadData()
-
Application.Exit()
-
End Sub
-
End Class
Figured it out! Here's the working code in case anyone needs: - Imports System.IO
-
Imports System.Data.OleDb
-
Public Class Update2
-
Sub LoadData()
-
Dim objStreamReader As StreamReader = File.OpenText("/CMgmt/import.csv")
-
While objStreamReader.Peek() <> -1
-
Dim Str1() As String = Split(objStreamReader.ReadLine(), ",")
-
AddRecord(Str1(0), Str1(1), Str1(2), Str1(3), Str1(4), Str1(5), Str1(6))
-
End While
-
objStreamReader.Close()
-
End Sub
-
Sub AddRecord(ByVal first As String, ByVal last As String, ByVal address As String, ByVal postal As String, ByVal city As String, ByVal prov As String, ByVal tel As String)
-
Dim objConnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=/CMgmt/CMgmt.mde")
-
objConnection.Open()
-
Dim SQL As String = "INSERT INTO Import_T VALUES ('" & first & "','" & last & "','" & address & "','" & postal & "','" & city & "','" & prov & "','" & tel & "')"
-
-
-
-
Dim objCommand As OleDbCommand
-
objCommand = New OleDbCommand(SQL, objConnection)
-
objCommand.ExecuteNonQuery()
-
objConnection.Close()
-
End Sub
-
-
Private Sub Update2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
Me.LoadData()
-
Application.Exit()
-
End Sub
-
End Class
2 4464
Figured it out! Here's the working code in case anyone needs: - Imports System.IO
-
Imports System.Data.OleDb
-
Public Class Update2
-
Sub LoadData()
-
Dim objStreamReader As StreamReader = File.OpenText("/CMgmt/import.csv")
-
While objStreamReader.Peek() <> -1
-
Dim Str1() As String = Split(objStreamReader.ReadLine(), ",")
-
AddRecord(Str1(0), Str1(1), Str1(2), Str1(3), Str1(4), Str1(5), Str1(6))
-
End While
-
objStreamReader.Close()
-
End Sub
-
Sub AddRecord(ByVal first As String, ByVal last As String, ByVal address As String, ByVal postal As String, ByVal city As String, ByVal prov As String, ByVal tel As String)
-
Dim objConnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=/CMgmt/CMgmt.mde")
-
objConnection.Open()
-
Dim SQL As String = "INSERT INTO Import_T VALUES ('" & first & "','" & last & "','" & address & "','" & postal & "','" & city & "','" & prov & "','" & tel & "')"
-
-
-
-
Dim objCommand As OleDbCommand
-
objCommand = New OleDbCommand(SQL, objConnection)
-
objCommand.ExecuteNonQuery()
-
objConnection.Close()
-
End Sub
-
-
Private Sub Update2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
Me.LoadData()
-
Application.Exit()
-
End Sub
-
End Class
I guess I am seeing double. Please refrain from posting your questions twice.
Thanks,
CroCrew~
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Joel |
last post by:
Hi,
I'm importing our DOS data base (Dataflex) to Mysql I have a table with
174,638 records that I convert into a tab delimetered Text file however,
Mysql only reads 87,035! I checked the text...
|
by: Paul Scotchford |
last post by:
Env : SLQSERVER2000 - DTS
I want to import a text file with 3 fields in it ...
F1: Ident char(3)
F2: Note (Text) char(32,000) yeah big eh!
F3: Date
Field F2: has...
|
by: Edward S |
last post by:
I budget for a Project in an Excel sheet as illustrated below. The
months below are usually a 2 year period i.e. 24 months, though it
could be over 24 months depending upon a Project. I then...
|
by: sparks |
last post by:
I have never done this and wanted to ask people who have what is the
best way.
One person said import it to excel, then import it into access table.
but since this will be done a lot, I am...
|
by: Mike Collins |
last post by:
I am trying to export data from multiple tables in SQL Server to an XML file
so I can then import it to another database. It seems to be working fine for
exporting, but I am having trouble...
|
by: mukeshsrivastav |
last post by:
dear sir
i want to move form excel to access.
i have 5 excel file having same formats and fields.now i want to import all data in one access table.
importing one file is easy .but importing and...
|
by: Debbiedo |
last post by:
I have a text file that I am importing into an Access table that was
generatred from data exported from a Word file. Several (about 20-30)
fields are from check boxes on the Word form. These fields...
|
by: tom.hepworth |
last post by:
Hi
I have a problem which I hope someone can help me with because I
really don't even know where to start with it.
I am using Access 2003. I have a delimited text file which contains
about...
|
by: johnporter123 |
last post by:
Does anyone have a method of importing a large "FLAT" CSV file into access. The file has well over 255 columns (Fields). Before anyone flames me over normalization, I do not have access to the...
|
by: Harshe |
last post by:
hello all,
I am trying to code, but i am just stuck after importing one sheet. so here is the gist of what i need help with.
In a workbook at the start of the year (january) i will have 4...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |