Seb Posted April 12, 2004 Posted April 12, 2004 (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 April 12, 2004 by Seb Quote
Moderators Robby Posted April 12, 2004 Moderators Posted April 12, 2004 Is this a web form or WinForm? Quote Visit...Bassic Software
Moderators Robby Posted April 12, 2004 Moderators Posted April 12, 2004 Does File_TextBox contain the full path ? Quote Visit...Bassic Software
Moderators Robby Posted April 12, 2004 Moderators Posted April 12, 2004 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 Quote Visit...Bassic Software
Seb Posted April 12, 2004 Author Posted April 12, 2004 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? Quote
Moderators Robby Posted April 13, 2004 Moderators Posted April 13, 2004 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. Quote Visit...Bassic Software
Seb Posted April 18, 2004 Author Posted April 18, 2004 (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 April 19, 2004 by PlausiblyDamp Quote
Moderators Robby Posted April 18, 2004 Moderators Posted April 18, 2004 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" Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.