我该如何避免这种代码?

时间:2015-10-17 04:38:18

标签: c# code-cleanup

如何避免这种编码?

我不知道将数据库中的所有存储值放入所需文本框的查询类型。

如何排除数据库表中的字段?我在我的桌子上有50个字段,我只希望其中45个字段显示在texbox中,所以将来我不喜欢手动编码,我想避免编码这样丑陋,有没有捷径排除他们的代码?

  void grdViewStudents_DoubleClick(object sender, EventArgs e)
    {

        if (grdViewStudents.SelectedRows.Count == 1)
        {
                 dtpDate.Value.ToLongTimeString()
                 txtFamName.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtFirstName.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtMidName.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtSchoolID.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 cmbCourse.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 cmbMajor.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 cmbYear.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 dtpBirthday.Value.ToShortDateString()
                 cmbSem.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtSY.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtSum.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 cmbGender.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 cmbCivil.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtNationality.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtHomeAdd.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtPermaAdd.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtContact.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtEmailAdd.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 cmbReligion.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 cmbStudentStatus.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtSchoolLast.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtTerm.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtAcadYR.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtScholar.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtFather.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtFatherAdd.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtFatherJob.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtMother.Text =cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtMotherAdd.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtMotherJob.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtGuardianName.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtGuardianRelation.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtGuardianContact.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtGuardianAdd.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtRespPerson.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtRespPersonRelation.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtRespPersonAdd.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtRespPersonContact.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtEmployerName.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtEmployerAdd.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtElemName.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtElemAdd.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 dtpElemYear.Value.ToString("yyyy")
                 txtHiSkulName.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtHiSkulAdd.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 dtpHiSkulYear.Value.ToString("yyyy")
                 txtCollegeName.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 txtCollegeAdd.Text=cfgotcall.tbl.Rows[0]["FamilyName"].ToString();
                 dtpCollegeYear.Value.ToString("yyyy")
        }
    }

1 个答案:

答案 0 :(得分:1)

你可以使用entityframework来避免这种编码。