| | |
load bulk data files into mysql dynamically
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2007
Posts: 13
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Oct 2007
Posts: 13
Reputation:
Solved Threads: 0
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()
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()
•
•
Join Date: Oct 2007
Posts: 13
Reputation:
Solved Threads: 0
•
•
•
•
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.
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"
"C:\Data\filename.txt"
![]() |
Similar Threads
- writitng data from php to mysql (PHP)
- Writing mp3 files to data files (OS X)
- How do I work with data files? (C#)
- Error message while importing data to Excel from the MySQL db (MySQL)
- Who knows all Outlook 2000 data files? (Windows Software)
- WinXP Re-install Problem (Windows NT / 2000 / XP)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: VB6 - Generate a new/blank sheet each time I execute my program.
- Next Thread: loading setup in another computer
Views: 3450 | Replies: 10
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
6 429 2007 access activex add age append application basic beginner birth c++ calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





