Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim connection As SqlConnection = Nothing Try Dim img As FileUpload = CType(QuestionUp, FileUpload) Dim imgByte As Byte() = Nothing If img.HasFile AndAlso Not img.PostedFile Is Nothing Then 'To create a PostedFile Dim File As HttpPostedFile = QuestionUp.PostedFile 'Create byte Array with file len imgByte = New Byte(File.ContentLength - 1) {} 'force the control to load data in array File.InputStream.Read(imgByte, 0, File.ContentLength) End If ' Insert the employee name and image into db Dim conn As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString connection = New SqlConnection(conn) connection.Open() Dim sql As String = "INSERT INTO QN_QUESTION_MAST(QUES_CODE,Ques_ImageData) VALUES(@QUES_CODE, @Ques_ImageData) SELECT @@IDENTITY" Dim cmd As SqlCommand = New SqlCommand(sql, connection) cmd.Parameters.AddWithValue("@QUES_CODE", txtQuestionCode.Text) cmd.Parameters.AddWithValue("@Ques_ImageData", imgByte) Dim id As Integer = Convert.ToInt32(cmd.ExecuteScalar()) lblMsg.Text = String.Format("QUES_CODE is {0}", id) Image2.ImageUrl = "~/ShowImage.ashx?id=" & id Catch lblMsg.Text = "There was an error" Finally connection.Close() End Try End Sub
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)