3 Replies - 3114 Views - Last Post: 30 April 2011 - 10:43 AM Rate Topic: -----

#1 hemo  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 70
  • Joined: 02-January 07

Connecting to MySql with asp FileUpload

Posted 29 April 2011 - 09:09 AM

I am trying with the below code,to upload files to my database but having difficulty with the connection to remote mysql database. My normal connection code in Web.Config.
<add name=”connStringName” connectionString=”Database =databasename Sourse=00.000.00.0;port=0000;uid=xxxxxx;Password=xxxxxx;”providername=”MySql.Data.MySqlClient” />

works OK using sql INSERT INTO the fields.
My database has 3 fields ID, Fileno, filename.

My problem is using the above connection with the below upload code to upload the whole file.

<script runat="server">

    Protected Sub Button1_Click(ByVal sender As Object, _

      ByVal e As System.EventArgs)

        If FileUpload1.HasFile Then

            Try

                FileUpload1.SaveAs("C:\Uploads\" & _

                   FileUpload1.FileName)

                Label1.Text = "File name: " & _

                   FileUpload1.PostedFile.FileName & "<br>" & _

                   "File Size: " & _

                   FileUpload1.PostedFile.ContentLength & " kb<br>" & _

                   "Content type: " & _

                   FileUpload1.PostedFile.ContentType

            Catch ex As Exception

                Label1.Text = "ERROR: " & ex.Message.ToString()

            End Try

        Else

            Label1.Text = "You have not specified a file."

        End If

    End Sub

</script>

 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Upload Files</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <asp:FileUpload ID="FileUpload1" runat="server" /><br />

        <br />

        <asp:Button ID="Button1" runat="server" onclick="Button1_Click"

         Text="Upload File" /> <br />

        <br />

        <asp:Label ID="Label1" runat="server"></asp:Label></div>

    </form>

</body>

</html>


hemo

This post has been edited by hemo: 29 April 2011 - 10:37 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Connecting to MySql with asp FileUpload

#2 macosxnerd101  Icon User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12298
  • View blog
  • Posts: 45,399
  • Joined: 27-December 08

Re: Connecting to MySql with asp FileUpload

Posted 30 April 2011 - 09:06 AM

Moved to ASP.NET.
Was This Post Helpful? 0
  • +
  • -

#3 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: Connecting to MySql with asp FileUpload

Posted 30 April 2011 - 09:25 AM

looks like you may have a typo, "Sourse=00.000.00.0", might should be Source. Also in your code I can see where you're saving the file, but I don't see where you're trying to upload it to a database anywhere.

This post has been edited by Nakor: 30 April 2011 - 09:38 AM

Was This Post Helpful? 0
  • +
  • -

#4 hemo  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 70
  • Joined: 02-January 07

Re: Connecting to MySql with asp FileUpload

Posted 30 April 2011 - 10:43 AM

Oops it seems I have made a bad start. Although I appreciate it's dealing with asp.net as I was seeking help for MySql database connection I considered it a post for that forum.

Yes, as you correctly point out sourse is a typo. My connection code has the correct ‘source’ as mentioned it operates OK with other sql statements.

The file to be uploaded is located on the C: drive and selected by means of the browse button in asp.FileUpload. The destination of the file to be uploaded is my remote MySql database, Table name: files, field name: filename (type longtext).

As must be obvious, this is my first attempt with FileUload, but hopefully with determination I will get there!

hemo

This post has been edited by hemo: 30 April 2011 - 10:43 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1