Access DB Insert problem

Discussion in 'Databases' started by clothesofch, Feb 4, 2006.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Please help! I cannot get an insert to work on my Access DB. I have verified that the sqlis ok. I'm not getting any compile errors or errors when I click the button to do the insert. Here's my code:




    protected void Button1_Click(object sender, EventArgs err)


    {


    string Message = null;





    OleDbConnection myConnection = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Source=clothesofchrist.mdb;");


    OleDbCommand mySqlCommand = new OleDbCommand("INSERT INTO prayer_requests (Name) Values ('Bob Dylan')", myConnection);


    OleDbCommand mySqlCleanup = new OleDbCommand("DELETE FROM prayer_requests WHERE Name = 'Bob Dylan'", myConnection);


    try


    {


    myConnection.Open();


    mySqlCleanup.ExecuteNonQuery(); .


    mySqlCommand.ExecuteNonQuery();


    Message = "New Record inserted into prayer_requests table in clothesofchrist.";


    }


    catch (Exception errorr)


    {


    Message = "Couldn't insert record: " + errorr.ToString();


    }


    finally


    {


    myConnection.Close();


    }


    Console.Write(Message);








    }
     
  2. Have you verified the application is running that method? Try changing your method to




    protected void Button1_Click(object sender, EventArgs err)


    {


    throw new Exception("Button1_Click");


    }





    ... and see if this is being fired.


    Joel Thoms

    DiscountASP.NET
    http://www.DiscountASP.NET
     
  3. Thanks for the reply. I fixed the problem last night. I added the full mapped path to the data source parameter and had to add a @ to the string for C# to ignore the slashes as special characters. This might be something good to add to the knowledge base if it isn't there. A programmer at work showed the @ to me, but I had looked all over the internet and hadn't come across an example using it.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page