473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

importing csv to mdb file - multiple fields

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?


Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2. Imports System.Data.OleDb
  3. Public Class Update2
  4.     Sub LoadData()
  5.         Dim objStreamReader As StreamReader = File.OpenText("/CMgmt/import.csv")
  6.         While objStreamReader.Peek() <> -1
  7.             Dim Str1() As String = Split(objStreamReader.ReadLine(), ",")
  8.             AddRecord(Str1(0), Str1(1), Str1(2), Str1(3), Str1(4), Str1(5), Str1(6))
  9.         End While
  10.         objStreamReader.Close()
  11.     End Sub
  12.     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)
  13.         Dim objConnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=/CMgmt/CMgmt.mdb")
  14.         objConnection.Open()
  15.         Dim SQL As String = "INSERT INTO [Import_T](first,last,address,postal,city,prov,tel) VALUES ('" & first & "','" & last & "','" & address & "','" & postal & "','" & city & "','" & prov & "','" & tel & "')"
  16.         Dim objCommand As OleDbCommand
  17.         objCommand = New OleDbCommand(SQL, objConnection)
  18.         objCommand.ExecuteNonQuery()
  19.         objConnection.Close()
  20.     End Sub
  21.  
  22.     Private Sub Update2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  23.         Me.LoadData()
  24.         Application.Exit()
  25.     End Sub
  26. End Class
Feb 11 '10 #1

✓ answered by penseur11

Figured it out! Here's the working code in case anyone needs:
Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2. Imports System.Data.OleDb
  3. Public Class Update2
  4.     Sub LoadData()
  5.         Dim objStreamReader As StreamReader = File.OpenText("/CMgmt/import.csv")
  6.         While objStreamReader.Peek() <> -1
  7.             Dim Str1() As String = Split(objStreamReader.ReadLine(), ",")
  8.             AddRecord(Str1(0), Str1(1), Str1(2), Str1(3), Str1(4), Str1(5), Str1(6))
  9.         End While
  10.         objStreamReader.Close()
  11.     End Sub
  12.     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)
  13.         Dim objConnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=/CMgmt/CMgmt.mde")
  14.         objConnection.Open()
  15.         Dim SQL As String = "INSERT INTO Import_T VALUES ('" & first & "','" & last & "','" & address & "','" & postal & "','" & city & "','" & prov & "','" & tel & "')"
  16.  
  17.  
  18.  
  19.         Dim objCommand As OleDbCommand
  20.         objCommand = New OleDbCommand(SQL, objConnection)
  21.         objCommand.ExecuteNonQuery()
  22.         objConnection.Close()
  23.     End Sub
  24.  
  25.     Private Sub Update2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  26.         Me.LoadData()
  27.         Application.Exit()
  28.     End Sub
  29. End Class

2 4464
Figured it out! Here's the working code in case anyone needs:
Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2. Imports System.Data.OleDb
  3. Public Class Update2
  4.     Sub LoadData()
  5.         Dim objStreamReader As StreamReader = File.OpenText("/CMgmt/import.csv")
  6.         While objStreamReader.Peek() <> -1
  7.             Dim Str1() As String = Split(objStreamReader.ReadLine(), ",")
  8.             AddRecord(Str1(0), Str1(1), Str1(2), Str1(3), Str1(4), Str1(5), Str1(6))
  9.         End While
  10.         objStreamReader.Close()
  11.     End Sub
  12.     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)
  13.         Dim objConnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=/CMgmt/CMgmt.mde")
  14.         objConnection.Open()
  15.         Dim SQL As String = "INSERT INTO Import_T VALUES ('" & first & "','" & last & "','" & address & "','" & postal & "','" & city & "','" & prov & "','" & tel & "')"
  16.  
  17.  
  18.  
  19.         Dim objCommand As OleDbCommand
  20.         objCommand = New OleDbCommand(SQL, objConnection)
  21.         objCommand.ExecuteNonQuery()
  22.         objConnection.Close()
  23.     End Sub
  24.  
  25.     Private Sub Update2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  26.         Me.LoadData()
  27.         Application.Exit()
  28.     End Sub
  29. End Class
Feb 11 '10 #2
CroCrew
564 Expert 512MB
I guess I am seeing double. Please refrain from posting your questions twice.

Thanks,
CroCrew~
Feb 12 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
1
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...
9
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...
1
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...
5
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...
3
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...
2
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...
5
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...
4
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...
4
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.