LOAD DATA INFILE ASP.NET
Posted by: Matthew Gonzalez
Date: July 05, 2012 02:13PM

I am having trouble using the MySql data connection to make a button onclick to run a query.

So basically I am making an application to easily update our MySql database by having the user upload the txt file (Tab Delimited), and then once its uploaded they are redirected to another page (import.aspx) that has a button.

When clicked this button is supposed to connect to the MySql database and implement the LOAD DATA INFILE statement to grab the file uploaded and use that as the source for the statement.

I can't figure out how to connect to the database to do such a thing. I am using the connection method in the Web.Config file. basically, the statement would be something like:

LOAD DATA INFILE 'Server.mappath("~/uploads/Update.txt")' into table test; when the button is clicked. Since it is a tab-delimited file, would this statement change.

Below is the ASP Code I wrote.
Any help would be appreciated.

Thanks.

-Matt







====START CODE====

Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim connection As MySqlConnection = New MySqlConnection(ConfigurationManager.ConnectionStrings("TestConnectionString").ConnectionString)
Try
Dim path As String
path = Server.MapPath("~/uploads/Update.txt")
'path = path.Replace("/", "//")
Dim command As MySqlCommand = New MySqlCommand("LOAD DATA INFILE'" + path + "'into table names;", connection)
'SAMPLE SQL: LOAD DATA INFILE 'c:/wamp/www/upload/Update.txt' into table names;
connection.Open()
command.ExecuteNonQuery()
connection.Close()
Finally
If connection.State = ConnectionState.Open Then
connection.Close()
Response.Redirect("~/Default.aspx")
End If

End Try



End Sub

====END CODE====

Options: ReplyQuote


Subject
Written By
Posted
LOAD DATA INFILE ASP.NET
July 05, 2012 02:13PM
July 26, 2012 02:18PM
July 26, 2012 02:26PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.