Dim UlFileName, NewFileName As String
If Me.FileUpload1.HasFile Then
UlFileName = "Uploads/" & FileUpload1.FileName
Me.FileUpload1.SaveAs(Server.MapPath(UlFileName))
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim strConnString, SQL As String
Dim Trans As SqlTransaction
Dim SVR As String = "HOME-632DB7B2A9\sqlExpress"
Dim UserID As String = "sa"
Dim password As String = "admins"
strConnString = "Server=" & SVR & ";UID=" & UserID & ";PASSWORD= " & password & ";database=leave;Max Pool Size=400;Connect Timeout=600;"
objConn.ConnectionString = strConnString
objConn.Open()
Trans = objConn.BeginTransaction(IsolationLevel.ReadCommitted)
With objCmd
.Connection = objConn
.Transaction = Trans '*** Command & Transaction ***'
End With
Try
SQL = "INSERT INTO tb_pic(picture)"
SQL &= " VALUES ('" & UlFileName.ToString & "')"
'Dim sqll As String = "INSERT INTO tb_username(signature)"
'sqll &= "VALUES( '" & FileUpload1.TemplateSourceDirectory & "')"
objCmd.CommandText = SQL
objCmd.CommandType = CommandType.Text
objCmd.ExecuteNonQuery()
Trans.Commit()
Catch ex As Exception
Trans.Rollback()
End Try
objConn.Close()
objConn = Nothing
End If
Me.Image1.Visible = True
Me.Image1.ImageUrl = UlFileName
End Sub