Graeme

Graeme

  • NA
  • 7
  • 0

Insert not working???

Dec 12 2007 4:15 PM

Hi I am trying my first windows application. I have created a connection string in my app.config. I have tried some test coding to see if my connection works prior to completing the coding for textbox/combobox insertions to my .sdf (sqlce) file.

Here is the code I used to test the connection:

private void btnInsertTestCert_Click(object sender, EventArgs e)

{

SqlCeConnection conn = null;

string cnString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;

try

{

conn = new SqlCeConnection(cnString);

conn.Open();

SqlCeCommand cmd = conn.CreateCommand();

cmd.CommandText = "INSERT INTO tblTestCert (HoseNumber, Customer, HoseType, TestedTo)Values('1', 'Albion', 'Chemical', '225')";

cmd.ExecuteNonQuery();

}

finally

{

conn.Close();

}

}

I assume the connection works fine as I get no error, yet when I view table data there is no record in the database??

Yet if I click the click event button twice I get a duplicate value error

Any idea what I'm doing wrong???


Answers (7)