[ create a new paste ] login | about

Link: http://codepad.org/KmNlj83n    [ raw code | fork | 20 comments ]

code_oxide - C++, pasted on Jul 6:
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();


            


           //bool set = false;
            dsl = new DataSet();
            
            
           
           // string sql = "CREATE TABLE apparel(item_code int,item_price int,item_name text,item_size text)";
             
            //string vsql = "SELECT MSysObjects.Type, MSysObjects.Flags, MSysObjects.Name FROM MSysObjects WHERE (((MSysObjects.Type)=1) AND ((MSysObjects.Flags)=0));";
        
            
             //  da = new System.Data.OleDb.OleDbDataAdapter(sql, con);
               
            
           // OleDbCommand cmdda = new OleDbCommand(sql, con);
           // OleDbCommand cmdea = new OleDbCommand(vsql, con);
            
            con.Open();

            DataTable table2 = con.GetSchema("tables");
    
            //cmdda.ExecuteNonQuery();
           // cmdea.ExecuteNonQuery();

            MessageBox.Show("Database Open");
            //da.Fill(dsl, "clothes");
            //ea.Fill(esl, "clothes1");
            
          
           // dataGridView1.DataSource = esl.Tables["clothes1"];
            
            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();
            
       
        }

    }
}


Create a new paste based on this one


Comments:
posted by code_oxide on Jul 6
wat function u were twlling

reply
posted by code_oxide on Jul 6
try removing the con.dispose line

reply
posted by code_oxide on Jul 6
con.Open in the fucntion tabledel not working giving this error
The ConnectionString property has not been initialized.
reply
posted by code_oxide on Jul 6
not working tried disposing that dispose.
reply
posted by code_oxide on Jul 6
try redefining the con inside the tabledel function

reply
posted by code_oxide on Jul 6
you mean re typin conn string in the func tabledel
reply
posted by code_oxide on Jul 6
yeah

reply
posted by code_oxide on Jul 6
try breaking point
reply
posted by code_oxide on Jul 6
yeah
reply
posted by code_oxide on Jul 6

reply
posted by code_oxide on Jul 6
wat happened da
reply
posted by code_oxide on Jul 6
did that matrix funct work for u
reply
posted by code_oxide on Jul 6
i tried break points . see when i hover over con in the fucntion , it properly says the con belong. It's not even showing as an error. Used Brek points and it stops at con.Open.It even stores the sql query in vsql properly . Checked that with immediate window.
reply
posted by code_oxide on Jul 6
k did u paste the con def inside function and try
reply
posted by code_oxide on Jul 6
you can't have two conn defn's . I tried pasting it into the new one in the func. Then first one becomes inactive and stff.
reply
posted by code_oxide on Jul 6
try giving diff name inside function for the new con def
reply
posted by code_oxide on Jul 6
dont close the con keep it open and try , this ll work
reply
posted by code_oxide on Jul 6
dataGridView1.DataSource = table2;

con.Close();
con.Dispose();
delete th above two lines and con.open()
in the func

reply
posted by code_oxide on Jul 6
reply
posted by code_oxide on Jul 6
dai p cos of ur question my reputation was spoiled
reply