dataadapter更新方法无法正常工作

时间:2014-09-22 11:48:56

标签: sql winforms ado.net dataadapter

我有DataSet我试图用它来更新sql db。

当我调用数据集的数据适配器方法的更新方法时。后端数据库不会更新。

为了进一步测试这个问题,我创建了一个名为rowsAffected的变量:

int rowsAffected = private_EnrolleeTableAdapter1.Update(enrollee);

当我运行代码但数据库未更新时,变量返回1.

关于我可能做错的任何想法?

代码如下:

//Create new employee record(row) on Private_Enrollee table in database
HMODataSet.Private_EnrolleeRow enrollee = HMODataSet.Private_Enrollee.NewPrivate_EnrolleeRow();
enrollee.Title = title;
enrollee.Firstname = firstname;
enrollee.Othername = middlename;
enrollee.Surname = surname;
enrollee.Sex = sex;
enrollee.Date_of_Birth = dateofbirth;
enrollee.Office_Tel = officetel;
enrollee.Residential_Tel = restel;
enrollee.Mobile_Tel = mobtel;
enrollee.Email_Address = email;
enrollee.Marital_Status = maritalstatus;
enrollee.Occupation = occupation;
enrollee.NextOfKin_Name = nextofkin;
enrollee.Relationship = relationship;
enrollee.Next_of_Kin_Address = address;
enrollee.Next_of_Kin_Telephone_No = nextofkintelno;
enrollee.Address = address;
enrollee.Town = town;
enrollee.City = city;
enrollee.State = state;
enrollee.Country = country;
enrollee.Hospital = healthcareprovider;
enrollee.Proposed_Plan_Type = proposedinsuranceplan;
enrollee.Blood_Group = bloodgroup;
enrollee.Genotype = genotype;
enrollee.Pre_Informed_Illness = preinformedillness;
enrollee.Existing_Chronic_Illness = chronicdisease;
enrollee.Enrollee_Type = enrolleetypeid;
enrollee.Enrollee_Type_ID = enrolleetypeid;
enrollee.Occupation = occupation;
enrollee.Designation = designation;
enrollee.Employer = employer;

HMODataSet.Private_Enrollee.AddPrivate_EnrolleeRow(enrollee);

int rowsAffected = private_EnrolleeTableAdapter1.Update(enrollee);

HMODataSet.AcceptChanges();

0 个答案:

没有答案