'*** Save to Database ***'
Dim objConn As OleDbConnection
Dim objCmd As OleDbCommand
Dim strConnString,strSQL As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("database/mydatabase.mdb")&";"
objConn = New OleDbConnection(strConnString)
objConn.Open()
strSQL = "INSERT INTO picture (PictureName) " & _
"VALUES ('" & fiUpload.FileName & "')"
objCmd = New OleDbCommand()
With objCmd
.Connection = objConn
.CommandType = CommandType.Text
.CommandText = strSQL
End With
objCmd.ExecuteNonQuery()
objCmd = Nothing
objConn.Close()
objConn = Nothing
Public Class FormUploadImage
Inherits System.Web.UI.Page
Dim dr As SqlDataReader
Dim strConn As String = WebConfigurationManager.ConnectionStrings("testQC").ConnectionString
Dim conn As New SqlConnection(strConn)
Dim cmd As New SqlCommand
Dim dt As New DataTable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Sub btnUpload_OnClick(ByVal sender As Object, ByVal e As EventArgs)
Me.pnlUpload.Visible = False
Me.pnlSave.Visible = True
If Me.fiUpload.HasFile = False Then
Me.lblText.Text = "Please select upload file!"
Else
Me.fiUpload.SaveAs(Server.MapPath("Myfiles/" & fiUpload.FileName))
Me.lblText.Text = "<b>" & fiUpload.FileName & "</b> Uploaded.<br>"
'*** Save to Database ***'
Dim strSQL As String
conn.Open()
strSQL = "INSERT INTO picture (PictureName) " & _
"VALUES ('" & fiUpload.FileName & "')"
With cmd
.Connection = conn
.CommandType = CommandType.Text
.CommandText = strSQL
End With
cmd.ExecuteNonQuery()
cmd = Nothing
conn.Close()
conn = Nothing
Me.hplLink1.NavigateUrl = "FormUploadImage.aspx"
Me.hplLink2.NavigateUrl = "FormUploadImage2.aspx"
End If
End Sub