Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8952913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:58:45+00:00 2026-06-15T13:58:45+00:00

Any help? My code is as follows; Imports System.IO Imports System.Data Imports System.Data.SqlClient Imports

  • 0

Any help?
My code is as follows;

Imports System.IO
Imports System.Data
Imports System.Data.SqlClient 
Imports System.Data.OleDb

Partial Class Gallery
    Inherits System.Web.UI.Page

    Dim dbInsert As New OleDb.OleDbCommand
    Dim dbConnect As New OleDb.OleDbConnection
    Dim Line As String = Environment.NewLine
    Dim Message As String
    Dim dt As New DataTable()



    Protected Sub BtnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnUpload.Click

        Dim connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source = " & _
       Server.MapPath("App_Data\Web.accdb"))

        If FileUpload1.PostedFile IsNot Nothing Then
            Dim FileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
            Dim Picture As String = TxtPicturename.Text

            'Save files to disk
            FileUpload1.SaveAs(Server.MapPath("GalleryPics/" & FileName))

            Dim strQuery As String = "insert into Picture (FileName, FilePath)" _
             & " values(@FileName, @FilePath)"

            Dim cmd As New SqlCommand(strQuery)
            cmd.Parameters.AddWithValue("@FileName", FileName)
            cmd.Parameters.AddWithValue("@FilePath", "Gallery/" & FileName)
            cmd.CommandType = CommandType.Text

            Dim sql As String = "INSERT INTO Picture (PictureID, Picturename, CategoryNo) VALUES ('" & TxtPicturename.Text & "','" & FileUpload1.FileName & "');"
            dbInsert.CommandText = sql
            dbInsert.CommandType = CommandType.Text
            dbInsert.Connection = connection
            dbInsert.ExecuteNonQuery()
            MsgBox("Pictue successfully uploaded for " + Line + TxtPicturename.Text)

        End If

    End Sub
    Function checkFiletype(ByVal filename As String) As Boolean
        Dim ext As String = Path.GetExtension(filename)
        Select Case ext.ToLower()
            Case ".gif"
                Return True
            Case ".prg"
                Return True
            Case ".jpg"
                Return True
            Case "jpeg"
                Return True
            Case Else
                Return False
        End Select
    End Function

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load




    End Sub
End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:58:46+00:00Added an answer on June 15, 2026 at 1:58 pm

    You haven’t got an open connection to your Database before trying to run your query.

    put dbConnect.Open() before trying to use your query.

    I.E

                dbConnect.Open() ''<------ HERE
                Dim cmd As New SqlCommand(strQuery)
                cmd.Parameters.AddWithValue("@FileName", FileName)
                cmd.Parameters.AddWithValue("@FilePath", "Gallery/" & FileName)
                cmd.CommandType = CommandType.Text
    

    Don’t forget to close it when you’re finished with it too… I.E

                dbInsert.ExecuteNonQuery()
                dbConnect.Close() '' <--------- HERE
    

    UPDATE

    See this tutorial for a good example of inserting.
    http://idealprogrammer.com/net-languages/code-samples/vbnet-aspnet-sql-command-insert-statement-source-code/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can any one help me with code that subtract 1 from a digit stored
Any help would be appreciated, I'm trying to convert the code below to C#,
Hey friends any one please help me for this issue.in this javascript code i
Please help me understand the following code snippet :- def any(l): whether any number
Is there any program code that can help me to pop up the virtual
Any help at all is appreciated here folks. I'm building a web app in
Any help here would be greatly appreciated. I have this table hospital Nurse |
Any help is appreciated. When using cfimage to generate a captcha, we keep his
Any help most appreciated, this is driving me insane. I'm doing exactly what I
Any help would be appreciated. I am looking for a way to programatically notified

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.