Quantcast
Channel: MySQL Forums - Connector/NET and C#, Mono, .Net
Viewing all articles
Browse latest Browse all 1451

LOAD DATA INFILE ASP.NET (no replies)

$
0
0
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====

Viewing all articles
Browse latest Browse all 1451

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>