I am trying to work on uploading images in SQL Server Database.Therez no error in the code though I encountered this while uploading the image @ runtime .....
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Following is the code I had written:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim FileName As String
Dim FileType As String
Dim namePosition As Int16
Dim stream As IO.Stream
stream = File1.PostedFile.InputStream
Dim uploadPostedFile(stream.Length) As Byte
stream.Read(uploadPostedFile, 0, stream.Length)
namePosition = File1.PostedFile.FileName.LastIndexOf("\") + 1
FileName = File1.PostedFile.FileName.Substring(namePosition)
FileType = File1.PostedFile.ContentType
Dim con As New SqlClient.SqlConnection("Server=sys2; initial catalog=master integrated security=ssPI")
Dim sqlstr As String
sqlstr = "INSERT INTO ImageFile(Description,DocumentFileName,DocumentFil e,DoumentFileType) Values(@Description,@DocumentFileName,@DocumentFil e,@DoumentFileType)"
Dim cmd As New SqlClient.SqlCommand(sqlstr, con)
cmd.Parameters.Add("@description", SqlDbType.NVarChar, 100).Value = TextBox1.Text
cmd.Parameters.Add("@DocumentFileName", SqlDbType.NVarChar, 50).Value = FileName
cmd.Parameters.Add("@DocumentFile", SqlDbType.Image, uploadPostedFile.Length).Value = uploadPostedFile
cmd.Parameters.Add("@DoumentFileType", SqlDbType.NVarChar, 50).Value = FileType
con.Open()
End Sub
Please help me in understand what cud bethe basic problem.
Appreciate your kind help in advance.
Regards,
Deepa