Avatar of ddrhoward
ddrhoward
 asked on

Pictures not loading

I have a html file that loads the pictures, but whenever I'm step thru my code, it throws up the error....
Connection string not properly initialized.. And truthfully I don't know what to do.
Dim fileName As String
        Dim fileType As String
        Dim namePosition As Int16
        Dim stream As IO.Stream
        Dim conn As New SqlClient.SqlConnection
        Dim Cmd As SqlClient.SqlCommand
 
 
        stream = file1.PostedFile.InputStream
        Dim uploadedFile(stream.Length) As Byte
 
        stream.Read(uploadedFile, 0, stream.Length)
 
        namePosition = file1.PostedFile.FileName.LastIndexOf("\") + 1
        fileName = file1.PostedFile.FileName.Substring(namePosition)
        fileType = file1.PostedFile.ContentType
 
 
        conn.ConnectionString = _
               ConfigurationSettings.AppSettings("ConnectionString")
        conn.Open()
 
 
        Dim command As SqlClient.SqlCommand = _
             New SqlClient.SqlCommand( _
                        "INSERT INTO tblFFImages (vchDescription, vchimage, vchcasenumber)Values(@vchdescription, @vchimage, @vchcasenumber", conn)
 
        command.Parameters.Add _
                ("@vchDescription", _
                SqlDbType.Text).Value = txtdescription.Text
 
        command.Parameters.Add _
                ("@vchcasenumber", _
                SqlDbType.Int).Value = txtcasenumber.Text
 
        command.Parameters.Add _
                ("@vchimage", _
                SqlDbType.Image, uploadedFile.Length).Value = uploadedFile
 
        command.ExecuteNonQuery()
        conn.Close()

Open in new window

ASP.NETVisual Basic.NET

Avatar of undefined
Last Comment
ddrhoward

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
ssjo22

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Bob Learned

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ddrhoward

ASKER
I was able tofind a solution.  I used a stored procedure instead.   But thanks for your help.
 connFF = New SqlConnection(Application("connFF"))
               Dim cmdLoad As SqlCommand = New SqlCommand("spFFLoadImages", connFF)
        cmdLoad.CommandType = CommandType.StoredProcedure
 
        Dim fileName As String
        Dim fileType As String
        Dim namePosition As Int16
        Dim stream As IO.Stream
 
 
        stream = file1.PostedFile.InputStream
        Dim uploadedFile(stream.Length) As Byte
        stream.Read(uploadedFile, 0, stream.Length)
 
        namePosition = file1.PostedFile.FileName.LastIndexOf("\") + 1
        fileName = file1.PostedFile.FileName.Substring(namePosition)
        fileType = file1.PostedFile.ContentType
 
 
            If strcasenumber <> "" Then
                CheckDuplicateCaseNumber()
                If intcount >= 1 Then
                    lblmessage.Visible = True
                    lblmessage.Text = "Report Notes have been previously submitted for casenumber " + strcasenumber + "."
                    Exit Sub
                End If
            End If
 
            connFF.Open()
            With cmdNotes.Parameters
                .Add("@reportdate", dtreportdate)
                .Add("@DSFM", strDSFM)
                .Add("@casenumber", strcasenumber)
                .Add("@county", strcounty)
                .Add("@Notes", strnotes)
                .Add("@status", strstatus)
                .Add("@description", strdescription)
                .Add("@image", uploadedFile)
            End With

Open in new window

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck