We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,555 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

My C# window application cannot insert new record to sql database both in A

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())
            //{
            try
            {
                StaffData addstaff = new StaffData();

                addstaff.StaffName = txtUserName;
                addstaff.Sex = gender;
                addstaff.DateCreated = DateTime.Now;
                addstaff.Profession = txtProfession;
                addstaff.PhoneNumber = txtMobilePhone;
                addstaff.Address = txtAddress;
                mms.StaffDatas.AddObject(addstaff);
                mms.SaveChanges();
            }
            catch (Exception exp)
            {
                throw new Exception("ERROR: Unable to Add Staff - " + exp.Message.ToString(), exp);
            }
            //}
            return true;
        }
3
Contributors
2
Replies
1 Day
Discussion Span
3 Months Ago
Last Updated
20
Views
denmarkstan
Junior Poster in Training
60 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Post the SaveChanges() method. What error did you get?

ChrisHunter
Posting Pro
567 posts since Feb 2011
Reputation Points: 104
Solved Threads: 51
Skill Endorsements: 13

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 :)

arunkumars
Posting Whiz in Training
204 posts since Jul 2009
Reputation Points: 26
Solved Threads: 22
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0904 seconds using 2.78MB