An unhandled exception

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Haseeb Khan

    An unhandled exception

    am making a program where i insert the Value from text-boxes to my Access Database . em just having this Unusual error plz help me out

    My Data Base Connectiong Establishment

    Code:
    private OleDbConnection myCon; 
            public Form1()
            {
                InitializeComponent();
                string connetionString = null;
                OleDbConnection myCon = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Users/Mujahid/Documents/Visual Studio 2008/Projects/ts/ts/ts.accdb");
    And here is the Coding of my Button

    Code:
     private void button2_Click(object sender, EventArgs e)
            {
                OleDbCommand cmd = new OleDbCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText="insert into ts(ID,Name)" +"Values ('"+textBox1.Text+"','"+textBox2.Text+"')" ; 
                cmd.Connection=myCon;
                myCon.Open();  --> ERROR COMES OUT FROM HERE
                cmd.ExecuteNonQuery();
                myCon.Close();
                
            }
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    I'm not well versed in this stuff, but if you could post what the exception says that might give me a better idea of what's going on, or at the very least give someone who knows this area better an easier means of helping you out :)

    Comment

    Working...