2015-10-17 83 views
1

如何避免這種編碼?我該如何避免這種類型的代碼?

我不知道什麼樣的查詢將數據庫中的所有存儲值放入其所需的文本框中。

如何排除數據庫表中的字段?我在桌面上有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") 
     } 
    } 
+0

確實所有文本框都保持相同的值嗎? –

+0

您可以將它存儲在'object'中,而不是直接指定到'TextBox'中 –

+0

可能是'angularjs with asp.net' –

回答

1

您可以使用entityframework來避免這種編碼。