jagpreet 0 Newbie Poster

i have the following code for loading the csv file in to database dynamically.
that is i want to give the file path dynamically .


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 filePath As String

filePath = Me.filename.Text

conn.Open()


myCommand.Connection = conn

myCommand.CommandText = "load data infile ''?f'' into table configparams columns terminated by ',' enclosed by '""' lines starting by '""'"


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

myCommand.ExecuteNonQuery()

this code is giving following error -

error- Parameter '?f''' must be defined.

plz help me out with this

jagpreet 0 Newbie Poster

thanks hoppy for ur advice..


i m trying to use the following code..........but it is giving some errors and moreover i just want to extract column no 4 and 6........how can i do this with this code?

lPublic Function SortCSVFileA(ByVal sSourceFile As String, ByVal sTargetFile As String, ByVal sOrderBy As String, Optional ByVal sDelimiter As String = ",", Optional ByVal bHasHeaders As Boolean = True, Optional ByVal iColumns As Long = 0) As Long
On Error GoTo Hell

Dim aFieldNames() As String
Dim Trash As String
Dim x As Long
Dim iFields As Long
Dim iFileNum As Long

' Open the original CSV file
Dim reader As StreamReader = _
New StreamReader("C:\DATA\d2.txt")


If bHasHeaders Then
' Get the field names
Line Input #iFileNum, Trash
Else
For x = 1 To iColumns
Trash = Trash & String$(5, Chr$(64 + x)) & sDelimiter
Next
Trash = Left$(Trash, Len(Trash) - Len(sDelimiter))
End If
aFieldNames = Split(Trash, sDelimiter)
iFields = UBound(aFieldNames) ' Counter

' Add field names to Recordset.
For x = 0 To iFields
oRS.Fields.Append(aFieldNames(x), adVarChar, 100) ' 100 characters length. add more if neccessary.
Next

' Open Recordset (must do after adding columns)
oRS.Open()

' Get the field values for the record
x = 0
Do While Not EOF(iFileNum)
Line Input #iFileNum, Trash ' Grab whole …

jagpreet 0 Newbie Poster

yeh its a csv file.
i heve attached it with this thread

jagpreet 0 Newbie Poster

can anyone provide me with the script for extracting columns from a text file.
the script needs to be in visual basic

jagpreet 0 Newbie Poster

can u help me out with any of these methods?

jagpreet 0 Newbie Poster

i have two data files which contain the values to be stored into the columns of the table .
these files are of same nature ,i.e their data needs to be put into the same table.
these files have data for 6 columns.
now i want to compare the data of only two columns and want to get the difference between these two columns only.
if we can compare these two files and get the difference between two columns before loading them into the table , then that would also be fine.

can u guys help me out with its code..

jagpreet 0 Newbie Poster

i have to load the two files into the same table not in two different tables.
then i want to compare the following thing
say c1 is column1,c2 is column 2
r1 is row1 and r2 is row2
now the values in the table r like this
c1r1 c2r1(data from file 1)
c2r2 c2r2( data from file 2)
now i want to get the difference between c2r1 and c2r2

jagpreet 0 Newbie Poster

i have done all those changes.
now it is giving the following error

Parameter '?f''' must be defined.

jagpreet 0 Newbie Poster

i have load two data files into a mysql table.now i want the compare the data from these two files (i.e want to compare a particular column of the table and want to get the difference between the values from these two files).
i dont know how to do this.can anyone help me out with this?

jagpreet 0 Newbie Poster

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.

jagpreet 0 Newbie Poster

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()
jagpreet 0 Newbie Poster

no path is not fixed and files are in txt.

jagpreet 0 Newbie Poster

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