-
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!
-
My best guess would be to try catCMD.ExecuteNonQuery after you declare the catcmd
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks