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()
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