Good day people! I have a problem with my C# window application.
I can't insert new record to database. I have sought for many tutorial in ADO.net and Entity Framework.
I have been tackling it in Entity Framework because that is my preference.
My piece of Entity Framework code would run successfully to insert new record.
When i go back-end to see the result; none is found.I am using Visual studio 2010.
And i developed the database through visual studio (the normal way of adding new item).
I have this piece of code:

public bool CreateStaff(string txtUserName, string gender, string txtProfession, string txtMobilePhone, string txtAddress)
            //using (MyHospDataEntities db = new MyHospDataEntities())
                StaffData addstaff = new StaffData();

                addstaff.StaffName = txtUserName;
                addstaff.Sex = gender;
                addstaff.DateCreated = DateTime.Now;
                addstaff.Profession = txtProfession;
                addstaff.PhoneNumber = txtMobilePhone;
                addstaff.Address = txtAddress;
            catch (Exception exp)
                throw new Exception("ERROR: Unable to Add Staff - " + exp.Message.ToString(), exp);
            return true;

Edited by denmarkstan: No code snippt

4 Years
Discussion Span
Last Post by arunkumars

also post the 'AddObject(addstaff)' method, may be there is a problem with connection establishing and record saving or may be you open the connection in savechanges().
Not a serious issue, we can help :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.