01.
Dim
UlFileName, NewFileName
As
String
02.
03.
If
Me
.FileUpload1.HasFile
Then
04.
05.
UlFileName =
"Uploads/"
& FileUpload1.FileName
06.
Me
.FileUpload1.SaveAs(Server.MapPath(UlFileName))
07.
08.
Dim
objConn
As
New
SqlConnection
09.
Dim
objCmd
As
New
SqlCommand
10.
Dim
strConnString, SQL
As
String
11.
Dim
Trans
As
SqlTransaction
12.
Dim
SVR
As
String
=
"HOME-632DB7B2A9\sqlExpress"
13.
Dim
UserID
As
String
=
"sa"
14.
Dim
password
As
String
=
"admins"
15.
16.
strConnString =
"Server="
& SVR &
";UID="
& UserID &
";PASSWORD= "
& password &
";database=leave;Max Pool Size=400;Connect Timeout=600;"
17.
18.
objConn.ConnectionString = strConnString
19.
objConn.Open()
20.
21.
Trans = objConn.BeginTransaction(IsolationLevel.ReadCommitted)
22.
With
objCmd
23.
.Connection = objConn
24.
.Transaction = Trans
25.
26.
End
With
27.
Try
28.
29.
SQL =
"INSERT INTO tb_pic(picture)"
30.
SQL &=
" VALUES ('"
& UlFileName.ToString &
"')"
31.
32.
33.
34.
objCmd.CommandText = SQL
35.
objCmd.CommandType = CommandType.Text
36.
objCmd.ExecuteNonQuery()
37.
Trans.Commit()
38.
39.
Catch
ex
As
Exception
40.
Trans.Rollback()
41.
42.
End
Try
43.
44.
objConn.Close()
45.
objConn =
Nothing
46.
47.
End
If
48.
49.
Me
.Image1.Visible =
True
50.
Me
.Image1.ImageUrl = UlFileName
51.
End
Sub