OleDBCommand


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: OleDBCommand

  1. #1
    Join Date
    Mar 2005
    Posts
    105

    OleDBCommand

    All,

    I'm creating a small app in C# that needs to insert data into an Access 2003 dB. Here's my code:

    public void dbConnection()
    {
    // Create db connection object
    OleDbConnection conn = new OleDbConnection();
    conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source= C:\NHA.mdb";

    // Make sure the db opens okay.
    try
    {
    conn.Open();
    }
    catch (Exception ex)
    {
    MessageBox.Show("Failed to connect to data source");
    }
    // Build a SQL Insert statement string for all the input-form field values.
    string str = "INSERT INTO Customers(firstname,lastname)VALUES(fname,lname)";
    OleDbCommand catCMD = new OleDbCommand(str, conn);
    finally
    {
    conn.Close();
    }
    fname and lname refers to the first and last name of the user, respectively. I have an event handler attached to the 'Submit' button like so:

    private void ncSubmit_Click(object sender, System.EventArgs e){dbConnection();}

    I run the app enter a first/last name hit the submit button and nothing updates to my database. Any ideas?

    Thanks in advance!

  2. #2
    Join Date
    Sep 2004
    Posts
    77
    My best guess would be to try catCMD.ExecuteNonQuery after you declare the catcmd

  3. #3
    Join Date
    Mar 2005
    Posts
    105
    Oops! Guess that would help huh...

    Thanks Mark!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center