Robert Omete
Robert Omete

Reputation: 64

Pass a value from textbox to entityframework insert method in windows form

I am using C# windows forms with entityframework 6.1.3 as the datasource.I am tryng to insert data into a windows form. I have searched for various guides but all of them show an example like this

   private void CreateCash(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
    {
        LegalGridView.AddNewRow();
        LegalGridView.ShowPopupEditForm();
        var CashBookCreate = new CashBook 
        {
            CashTransact = cashtransacts.Name


        };
        dbContext.CashBooks.Add(CashBookCreate);
        dbContext.SaveChanges();
    }
}

CashTransact is the name of my class and in that format it enters "Legal Fees" in the database but I want to substitute "Legal Fees" for the value in my textbox 'cashtransacts' which unfortunately when I replace it there as cashtransacts.Name instead gets me the name of the column instead of the value I type in?

Upvotes: 0

Views: 603

Answers (1)

Marc Johnston
Marc Johnston

Reputation: 1286

"value in my textbox"

The correct way to get a value from a textbox is TextBox.Text.

The TextBox.Name will only return the name of the control that you provided it.

Upvotes: 1

Related Questions