User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 456,541 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,276 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 2133 | Replies: 10
Reply
Join Date: Oct 2007
Posts: 13
Reputation: jagpreet is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
jagpreet jagpreet is offline Offline
Newbie Poster

load bulk data files into mysql dynamically

  #1  
Oct 11th, 2007
i want to load bulk data files dynamically inot mysql database by using visual basic as front end.
i want to get the filepaths dynamically i.e i just enter the file name into textbox and it will automatically load the data into the database.
i have written this code


myCommand.CommandText = "LOAD DATA INFILE '?filename' into table configparams columns terminated by ',' enclosed by '""' lines starting by '""'"

myCommand.Connection = conn

myCommand.Parameters.AddWithValue("?filename", filename)
but with this code is not able to get the desired filepath

can anyone help me out plz
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2006
Location: United States
Posts: 613
Reputation: binoj_daniel is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 15
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: load bulk data files into mysql dynamically

  #2  
Oct 11th, 2007
Do you have a fixed path for the data files? And in what format are these files? .CSV or TXT?
Reply With Quote  
Join Date: Oct 2007
Posts: 13
Reputation: jagpreet is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
jagpreet jagpreet is offline Offline
Newbie Poster

Re: load bulk data files into mysql dynamically

  #3  
Oct 12th, 2007
no path is not fixed and files are in txt.
Reply With Quote  
Join Date: Dec 2006
Location: United States
Posts: 613
Reputation: binoj_daniel is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 15
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: load bulk data files into mysql dynamically

  #4  
Oct 12th, 2007
So how do you know where to look for the file if you dont know the path?
Reply With Quote  
Join Date: Dec 2006
Location: United States
Posts: 613
Reputation: binoj_daniel is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 15
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: load bulk data files into mysql dynamically

  #5  
Oct 12th, 2007
Also how do you get this filename?
Reply With Quote  
Join Date: Oct 2007
Posts: 13
Reputation: jagpreet is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
jagpreet jagpreet is offline Offline
Newbie Poster

Re: load bulk data files into mysql dynamically

  #6  
Oct 15th, 2007
this is what i want to do dynamically with the help of parameters.
what i want is that user just enter the filename along with the path in the textbox and then the code automatically put the data of the file into database.


i can also fix the path the path of the file but i want the filename dynamically.

i have written this code.


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim conn As New MySqlConnection
Dim myCommand As New MySqlCommand
Dim myAdapter As New MySqlDataAdapter
Dim myData As New DataTable

conn = New MySqlConnection()
conn.ConnectionString = "server=localhost " & ";" _
& "user id= root " & ";" _
& "password= cricket" & ";" _
& "database=systemconfiguration"

Dim filename As String

Dim fs As FileStream = New FileStream(textbox.text, FileMode.Open, FileAccess.Read)
(textbox.text is a textbox through which i want to give the filename or full filepath.)


FileSize = fs.Length
rawData = New Byte(FileSize) {}
fs.Read(rawData, 0, FileSize)
fs.Close()

myCommand.Connection = conn
myCommand.CommandText = "LOAD DATA INFILE '?f' into table configparams columns terminated by ',' enclosed by '""' lines starting by '""'"



myCommand.Parameters.AddWithValue("?f", filename)


conn.Open()
myCommand.ExecuteNonQuery()
Reply With Quote  
Join Date: Oct 2007
Posts: 13
Reputation: jagpreet is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
jagpreet jagpreet is offline Offline
Newbie Poster

Re: load bulk data files into mysql dynamically

  #7  
Oct 15th, 2007
Originally Posted by jagpreet View Post
this is what i want to do dynamically with the help of parameters.
what i want is that user just enter the filename along with the path in the textbox and then the code automatically put the data of the file into database.


i can also fix the path the path of the file but i want the filename dynamically.

i have written this code.


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim conn As New MySqlConnection
Dim myCommand As New MySqlCommand
Dim myAdapter As New MySqlDataAdapter
Dim myData As New DataTable

conn = New MySqlConnection()
conn.ConnectionString = "server=localhost " & ";" _
& "user id= root " & ";" _
& "password= cricket" & ";" _
& "database=systemconfiguration"

Dim filename As String

Dim fs As FileStream = New FileStream(textbox.text, FileMode.Open, FileAccess.Read)
(textbox.text is a textbox through which i want to give the filename or full filepath.)


FileSize = fs.Length
rawData = New Byte(FileSize) {}
fs.Read(rawData, 0, FileSize)
fs.Close()


(i can also get the filepath by this syntex given below

filePath = Me.filename.Text

MsgBox(filePath) )







myCommand.Connection = conn
myCommand.CommandText = "LOAD DATA INFILE '?f' into table configparams columns terminated by ',' enclosed by '""' lines starting by '""'"



myCommand.Parameters.AddWithValue("?f", filename)


conn.Open()
myCommand.ExecuteNonQuery()



everytime it is not able to find the correct path,infact it shows this error

File 'C:\Program Files\MySQL\MySQL Server 4.1\Data\systemconfiguration\?f' not found (Errcode: 22)



but when i hardcode the file path in the load query it works fine as it shown below

myCommand.CommandText = "load data infile 'C:/Documents and Settings/jagpreet/d2.txt' into table configparams columns terminated by ',' enclosed by '""' lines starting by '""'"



but whern i try to do it dynamically it gives the error.
Reply With Quote  
Join Date: Dec 2006
Location: United States
Posts: 613
Reputation: binoj_daniel is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 15
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: load bulk data files into mysql dynamically

  #8  
Oct 15th, 2007
Try to use a path which does not contain any spaces in the folder name. Let me know what happens, For eg: use the file path as :

"C:\Data\filename.txt"
Reply With Quote  
Join Date: Dec 2006
Location: United States
Posts: 613
Reputation: binoj_daniel is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 15
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: load bulk data files into mysql dynamically

  #9  
Oct 15th, 2007
It seems you are trying to connect to MySQL Database for this purpose.
Reply With Quote  
Join Date: Dec 2006
Location: United States
Posts: 613
Reputation: binoj_daniel is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 15
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: load bulk data files into mysql dynamically

  #10  
Oct 15th, 2007
Also Try replacing the single quote with 2 single quotes or a double quote. That should work.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Visual Basic 4 / 5 / 6 Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum

All times are GMT -4. The time now is 4:59 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC