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 7569139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:05:54+00:00 2026-05-30T15:05:54+00:00

I have the following code to insert some data from a GridView to a

  • 0

I have the following code to insert some data from a GridView to a oracle database.

Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInsert.Click
        Dim con = New OleDbConnection("Data Source=sml2; User ID=sfpl; Password=a; provider=OraOLEDB.Oracle")
        con.Open()
        For Each gvRow As GridViewRow In GridView1.Rows
            Dim trndate As Date = ddlTrnDte.SelectedValue
            Dim ZoneNo As Integer = ddlZone.SelectedValue
            Dim DocNo As TextBox = CType(gvRow.FindControl("txtDocNo"), TextBox)
            Dim VehCod As DropDownList = CType(gvRow.FindControl("ddlVeh"), DropDownList)
            Dim CircleNo As DropDownList = CType(gvRow.FindControl("ddlCircle"), DropDownList)
            Dim Contractor As DropDownList = CType(gvRow.FindControl("ddlContractor"), DropDownList)
            Dim Supplier As DropDownList = CType(gvRow.FindControl("ddlSupplier"), DropDownList)
            Dim NetWt As TextBox = CType(gvRow.FindControl("txtNetWt"), TextBox)
            Dim Rate As TextBox = CType(gvRow.FindControl("txtRate"), TextBox)
            Dim SNF As TextBox = CType(gvRow.FindControl("txtSNF"), TextBox)
            Dim FAT As TextBox = CType(gvRow.FindControl("txtFAT"), TextBox)
            Dim LR As TextBox = CType(gvRow.FindControl("txtLR"), TextBox)
            Dim TS As TextBox = CType(gvRow.FindControl("txtTS"), TextBox)
            'Create Connection


            Dim cmd As OleDbCommand = New OleDbCommand("Insert into MLK_02_01 (TRN_DTE,ZONE_NO,CIRCLE_NO,CNT_NO,DOC_NO,SUP_COD,VEH_NUM,NET_WEIGHT,Q_SNF,Q_FAT,Q_LR,Q_TS,RATE,veh_cod) VALUES (:TRN_DTE,:ZONE_NO,:CIRCLE_NO,:CNT_NO,:DOC_NO,:SUP_COD,:VEH_NUM,:NET_WEIGHT,:Q_SNF,:Q_FAT,:Q_LR,:Q_TS,:RATE,:veh_cod)", con)
            cmd.Parameters.Clear()
            'TrnDate
            cmd.Parameters.Add(":trn_dte", (OleDb.OleDbType.Date))
            cmd.Parameters(":trn_dte").Value = DateTime.Now()
            cmd.Parameters(":trn_dte").Value = ddlTrnDte.SelectedValue
            cmd.Parameters.AddWithValue(":ZONE_no", ZoneNo)
            cmd.Parameters.AddWithValue(":CIRCLE_no", CircleNo.SelectedValue)
            cmd.Parameters.AddWithValue(":CNT_no", Contractor.SelectedValue)
            cmd.Parameters.AddWithValue(":Doc_No", DocNo.Text)
            cmd.Parameters.AddWithValue(":sup_cod", Contractor.SelectedValue)
            cmd.Parameters.AddWithValue(":Veh_num", VehCod.SelectedItem.Text)
            cmd.Parameters.AddWithValue(":NET_WEIGHT", NetWt.Text)
            cmd.Parameters.AddWithValue(":Q_SNF", SNF.Text)
            cmd.Parameters.AddWithValue(":Q_FAT", FAT.Text)
            cmd.Parameters.AddWithValue(":Q_LR", LR.Text)
            cmd.Parameters.AddWithValue(":Q_TS", TS.Text)
            cmd.Parameters.AddWithValue(":rate", Rate.Text)
            cmd.Parameters.AddWithValue(":veh_cod", VehCod.SelectedValue)


            cmd.ExecuteNonQuery()
            Label1.Text = "All Records are Saved Successfully"
            con.Close()
            btnInsert.Enabled = False
        Next

    End Sub

Data is inserted into database fine but when the form is closed the database connection does not end. I need help in ending the database session to eliminate further communication errors.

  • 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-05-30T15:05:55+00:00Added an answer on May 30, 2026 at 3:05 pm

    You mention it’s a page, so I’m assuming this is an ASP page.

    IIS has database connection pooling enabled by default. This means that even though your code closed your connection, IIS maintains a connection in order to make the next query from the next request execute faster.

    To disable connection pooling, in your database connection string add this:

    Pooling=false

    New OleDbConnection("Data Source=sml2; User ID=sfpl; Password=a; provider=OraOLEDB.Oracle; Pooling=false")
    

    Also, after your execute change to this:

    cmd.ExecuteNonQuery()
    cmd.Dispose()
    

    After the con.Close():

    con.Close()
    con.Dispose()
    

    and that should dispose the command and connection objects.

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

Sidebar

Related Questions

I have table that I insert data with following query (from c# code): INSERT
I have the following code I use to insert form data into a single
I have the following code to fetch the data from URL, store it in
I have the following code: $sql = INSERT INTO table VALUES ('', ...); $result
I have the following test-code: CREATE TABLE #Foo (Foo int) INSERT INTO #Foo SELECT
I have the following Python code: cursor.execute("INSERT INTO table VALUES var1, var2, var3,") where
I have the following shortened classic ASP code that makes a SQL insert call...
I have not done much database programming at all. I am working from some
I have a database that has been populated with some data using create and
I am using the following script to import data into my mysql database from

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.