nickiii
05-23-2005, 12:22 PM
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!
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!