mardi 21 avril 2015

method completes but data is not inserted into SQL database

i have a method which should save user details to a local database on Visual Studio, the method below is in question

   private void btnSaveDetails_Click(object sender, EventArgs e)
    {
        //var IssueDate = this.dtpIssueDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "')";
        //var ExipryDate =this.dtpExpiryDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "')";
        var mainMenu = new frmMainMenu();
        SqlConnection sc = new SqlConnection();
        SqlCommand com = new SqlCommand();
        sc.ConnectionString = (Properties.Settings.Default.BioEngineering);
        sc.Open();
        com.Connection = sc;


        com.Parameters.AddWithValue("@Forename", this.txtFirstName.Text);
        com.Parameters.AddWithValue("@Surname", this.txtLastName.Text);
        com.Parameters.AddWithValue("@Company", this.txtCompany.Text);
        com.Parameters.AddWithValue("@SecurityLevel", this.cboSecurityLevel.Text);
        com.Parameters.AddWithValue("@IssueDate", this.dtpIssueDate.Value);
        com.Parameters.AddWithValue("@ExpiryDate", this.dtpExpiryDate.Value);
        com.Parameters.AddWithValue("@CardID", this.cboCardID.Text);

        com.CommandText = "INSERT INTO Users (Forename, Surname, Company, SecurityLevel, IssueDate, ExpiryDate, CardID) VALUES (@Forename,@Surname,@Company,@SecurityLevel,@IssueDate,@ExpiryDate,@CardID)";
        com.ExecuteNonQuery();
        sc.Close();
        this.Hide();
        mainMenu.Show();
    }

I get no errors and when i add a breakpoint at com.ExecuteNonQuery it appears to have the correct data....any ideas? i first thought it was the connection string but seen other sites with similar formats so dont think its it

Aucun commentaire:

Enregistrer un commentaire