Checkbox SelectedItem文本到Linq数据库

时间:2013-02-26 14:36:13

标签: c# asp.net linq

我构建了一个ASP.net用户控件,我试图从复选框中获取文本以传递给数据库。我的问题是我使用我使用的方法提交错误。这是我使用的:

            ResidenceHallInspection rhi = new ResidenceHallInspection();
            rhi.versionId = version.id;
            rhi.submitDate = DateTime.Now;
            rhi.CheckInOrOut = ddlCheck.SelectedItem.Text;
            rhi.StudentId = txtStudentId.Text;
            rhi.FirstName = txtFirstName.Text;
            rhi.MiddleName = txtMiddleName.Text;
            rhi.LastName = txtLastName.Text;
            rhi.Walls = chbxWalls.SelectedItem.Text;
            rhi.Windows = chbxWindows.SelectedItem.Text;
            rhi.Blinds = chbxBlinds.SelectedItem.Text;
            rhi.Couch = chbxCouch.SelectedItem.Text;
            rhi.CommonRoomCouch = chbxCRCouch.SelectedItem.Text;
            rhi.CommonRoomChair = chbxCRChair.SelectedItem.Text;
            rhi.Doors = chbxDoors.SelectedItem.Text;
            rhi.Carpet = chbxCarpet.SelectedItem.Text;
            rhi.Ceiling = chbxCeiling.SelectedItem.Text;
            rhi.CommonRoomCounter = chbxCRCounter.SelectedItem.Text;
            rhi.Cabinet = chbxCabinet.SelectedItem.Text;
            rhi.Phone = chbxPhone.SelectedItem.Text;
            rhi.Bed = chbxBed.SelectedItem.Text;
            rhi.Desk = chbxDesk.SelectedItem.Text;
            rhi.DeskChairs = chbxDeskChair.SelectedItem.Text;
            rhi.Tub = chbxTub.SelectedItem.Text;
            rhi.Vanity = chbxVanity.SelectedItem.Text;
            rhi.Notes = txtNotes.Text;
            rhi.Building = txtResHall.Text;
            rhi.ApartmentNumber = txtSuitNo.Text;
            rhi.BedSpace = txtBedSpace.Text;

             house.AddToResidenceHallInspections(rhi);
            house.SaveChanges()

1 个答案:

答案 0 :(得分:0)

最好能够看到更多信息,例如您收到的错误,以及自定义用户控件的代码和/或HTML。但是,似乎有几种可能性。一个是您的SelectedItem属性可能是null,这会导致ObjectReferenceException发生。另一个是Text本身为null,并且您的数据库不允许您分配的一个或多个字段的空值。

如果你提供更多信息,你可以得到一个比这更模糊的答案。