My Linq to Sql Insert code seems to work fine but I don't get a record in the database

Posted by Alex on Stack Overflow See other posts from Stack Overflow or by Alex
Published on 2010-06-09T02:52:11Z Indexed on 2010/06/09 3:02 UTC
Read the original article Hit count: 244

Filed under:

Here is my code. In the debugger, I can see that the code is running. No errors are thrown. But, when I go back to the table, no row has been inserted. What am I missing??

protected void submitButton_Click(object sender, EventArgs e)
{
    CfdDataClassesDataContext db = new CfdDataClassesDataContext();

    string sOfficeSought = officesSoughtDropDownList.SelectedValue;
    int iOfficeSought;
    Int32.TryParse(sOfficeSought, out iOfficeSought);

    Account act = new Account()
    {
        FirstName = firstNameTextBox.Text,
        MiddleName = middleNamelTextBox.Text,
        LastName = lastNameTextBox.Text,
        Suffix = suffixTextBox.Text,
        CampaignName = campaignNameTextBox.Text,
        Address1 = address1TextBox.Text,
        Address2 = address2TextBox.Text,
        TownCity = townCityTextBox.Text,
        State = stateTextBox.Text,
        ZipCode = zipTextBox.Text,
        Phone = phoneTextBox.Text,
        Fax = faxTextBox.Text,
        PartyAffiliation = partyAfilliatinoTextBox.Text,
        EmailAddress = emailTextBox.Text,
        BankName = bankNameTextBox.Text,
        BankMailingAddress = bankAddressTextBox.Text,
        BankTownCity = bankTownCityTextBox.Text,
        BankState = bankStateTextBox.Text,
        BankZip = bankZipTextBox.Text,
        TreasurerFirstName = treasurerFirstNameTextBox.Text,
        TreasurerMiddleName = treasurerMiddleNamelTextBox.Text,
        TreasurerLastName = treasurerLastNameTextBox.Text,
        TreasurerMailingAddress = treasurerMailingAddressTextBox.Text,
        TreasurerTownCity = treasurerTownCityTextBox.Text,
        TreasurerState = treasurerStateTextBox.Text,
        TreasurerZipCode = treasurerZipTextBox.Text,
        TreasurerPhone = treasurerPhoneTextBox.Text
        //OfficeSought = iOfficeSought
    };
    act.Suffix = suffixTextBox.Text;

    db.SubmitChanges();
}

© Stack Overflow or respective owner

Related posts about LINQ