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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:27:16+00:00 2026-06-07T00:27:16+00:00

this is my snippet , please help me why the con .open is not

  • 0

this is my snippet , please help me why the con .open is not working inside the function tabledel

i want to delete the table once i press the button , the connection gets opened for the first time but couldnt open it for the second time inside the function tabledel

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WFA_CREATE_DELETE
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        OleDbConnection con = new OleDbConnection(@"PROVIDER=Microsoft.ACE.OLEDB.12.0; Data Source=C:/Users/Dinesh/Documents/Database3.accdb");
        OleDbDataAdapter ea = new OleDbDataAdapter();
        DataSet dsl;
        DataSet esl;

        private void Form1_Load(object sender, EventArgs e)
        {
            OleDbDataAdapter da = new OleDbDataAdapter();
            dsl = new DataSet();
            con.Open();

            DataTable table2 = con.GetSchema("tables");

            MessageBox.Show("Database Open");

            dataGridView1.DataSource = table2;

            con.Close();
            con.Dispose();
        }

        public void Tabledel()
        {
            int a = 0, d = 0, count, itr;

            count = dataGridView1.RowCount;
            itr = dataGridView1.ColumnCount;

            while (a < count)
            {
                for (d = 0; d < itr; d++)
                {
                    if (dataGridView1.Rows[a].Cells[d].Value.ToString() == textBox1.Text)
                    {

                        MessageBox.Show("table exists");
                        esl = new DataSet();
                        string vsql = "drop table '" + textBox1.Text + "'";
                        ea = new System.Data.OleDb.OleDbDataAdapter(vsql, con);
                        OleDbCommand cmdea = new OleDbCommand(vsql, con);
                        //cmdea.Connection = con;

                        con.Open();
                        cmdea.ExecuteNonQuery();
                        MessageBox.Show("table dropped");
                        con.Close();
                        con.Dispose();
                    }
                }

                a++;
            }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        public void button1_Click(object sender, EventArgs e)
        {
           Tabledel();


        }

    }
}

link

  • 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-07T00:27:19+00:00Added an answer on June 7, 2026 at 12:27 am

    As I see you get this error:

    The ConnectionString property has not been initialized.
    

    May be you will create (dispose) your connection in somewhere else (except in form class global variable), so I suggest to set connection string explicitly (With recreating connection):

    con = new OleDbConnection(
          @"PROVIDER=Microsoft.ACE.OLEDB.12.0; Data Source=C:/Users/Dinesh/Documents/Database3.accdb");
    
    con.Open();
    

    Anyway it wasn’t hard to include main part of your code here in SO.

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

Sidebar

Related Questions

To understand what I mean, please see this snippet: <table style=width: 100%> <tbody><tr><td> <div
Below is my javascript code snippet. Its not running as expected, please help me
First of all, please help me out! I can not take this anymore. I
Can someone please help me, I have this xml snippet <?xml version=1.0 encoding=utf-8 ?>
This snippet of code always parses the date into the current timezone, and not
This is the code snippet I am trying to run. It is working fine
I have a DataGridView inside a ContextMenu control, please see the code snippet below:
Please help me out on this one, Im trying to produce 2 radio buttons
Please help with this issue of using NSFetchedResultsController. I created an object of NSFetchedResultsController
Please look at the following code snippet. I'm getting a nullreferenceexception at this.directories.Add(new directory(s));.

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.