Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I'm trying to get a button to upload an image to a database via a SQL connection. But I get the following:

 

"An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll

Additional information: Empty path name is not legal."

 

And the line in bold in this code is highlighted as the problem:

 

Private Sub Upload_Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Upload_Button.Click

 

Dim SQLreturn As Integer

Dim fsimage As System.IO.FileStream = New System.IO.FileStream(File_TextBox.Text, System.IO.FileMode.Open, System.IO.FileAccess.Read)Dim Picture(fsimage.Length) As Byte

fsimage.Read(Picture, 0, fsimage.Length)

 

Try

SqlConnection1.Open()

SqlCommand1.Parameters("@pictureTitle").Value = File_TextBox.Text

SqlCommand1.Parameters("@pictureDescription").Value = DescriptionBox.Text

SqlCommand1.Parameters("@pictureOwner").Value = System.Environment.UserName

SqlCommand1.Parameters("@pictureData").Value = Picture

 

SQLreturn = SqlCommand1.ExecuteNonQuery() 'command

 

Catch ex As Exception

MessageBox.Show(ex.Message)

Finally

SqlConnection1.Close()

End Try

 

 

If SQLreturn <> 1 Then

MessageBox.Show("Could not execute the INSERT query")

'results

 

Else

MessageBox.Show("INSERT completed successfully")

End If

File_TextBox.Clear()

End Sub

 

Any suggestions welcomed.

 

N.B. Also posted in Syntax forums by mistake, did not know how 2 delete from there.

Edited by Seb
  • Moderators
Posted

It should be either an absolute or relative path to the file.

Also try and explicitly cast your data types, for example Length is Long, but an Int is required.

Dim Picture(Convert.ToInt32(fsimage.Length)) AsByte

 

Visit...Bassic Software
Posted
When u say 'absolute or relative path to the file', do u mean the path of the file it came from or path in the database it's being put into?
  • Moderators
Posted

Path to the file, since the first argument in the FileStream states "absolute or relative path to the file"

 

The database should be fine since you already have a conn object that you are opening.

Visit...Bassic Software
Posted (edited)

Can't access the Server

 

Path to the file' date=' since the first argument in the FileStream states "[b']absolute or relative path to the file" [/b]

 

The database should be fine since you already have a conn object that you are opening.

 

I was wondering if u could look at the attached file to see if u can tell why I can't access the DB I have setup on the SQL Server. When I try to upload a file it says it 'can't access the server' even though it is running and I've setup the connection objects on each form that I think needs them.

 

Many Thanks in advance.

Edited by PlausiblyDamp
  • Moderators
Posted

Do a MessageBox() on whichever variable is holding the fileName and FilePath. Or Better still hard-code the value into your routine to make sure that is the problem (or not)

 

ie... "C:\images\myPic.jpg"

Visit...Bassic Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...