Jes Sie

Jes Sie

  • 702
  • 1.2k
  • 264.4k

Three Tier Structure (from code behind to data access)

Mar 5 2018 1:18 AM
Hello everyone, I created an xml file from a gridview (thanks to Rakesh article). My application is done using a 3 tier structure. How will I transfer my code behind to data access and call only the xml from my code behind? Please see code below.
 
  1. StringBuilder sbSubjects = new StringBuilder();  
  2.                 sbSubjects.AppendLine("<?xml version=\"1.0\" ?>");  
  3.   
  4.                 foreach (GridViewRow row in GridView1.Rows)  
  5.                 {  
  6.                     Label SubjectID = (Label)row.FindControl("lblSubjectId");  
  7.                     string lblEnrollmentId = lblEnrollmentID.Text.Trim();  
  8.   
  9.                     if (SubjectID == null || lblEnrollmentId == null)  
  10.                     {  
  11.                         return;  
  12.                     }  
  13.   
  14.                     if (string.IsNullOrEmpty(SubjectID.Text.Trim()) || string.IsNullOrEmpty(lblEnrollmentId))  
  15.                     {  
  16.                         return;  
  17.                     }  
  18.                     else  
  19.                     {  
  20.                         sbSubjects.AppendLine("<tblEnrolledSubjects>");  
  21.                         sbSubjects.AppendLine(" <subjects>");  
  22.                         sbSubjects.AppendLine("  <SubjectId>" + SubjectID.Text.Trim() + "</SubjectId>");  
  23.                         sbSubjects.AppendLine("  <EnrollmentID>" + lblEnrollmentId + "</EnrollmentID>");  
  24.                         sbSubjects.AppendLine(" </subjects>");  
  25.                         sbSubjects.AppendLine("</tblEnrolledSubjects>");  
  26.                     }  
  27.   
  28.                 }  
  29.                 SqlCommand cmdSubjects = new SqlCommand("[dbo].[spInsert_XML_BulkEnrollmentSubjects]", con, transaction);  
  30.                 cmdSubjects.CommandType = CommandType.StoredProcedure;  
  31.                 cmdSubjects.Parameters.AddWithValue("@SubjectsData", sbSubjects.ToString());  
 

Answers (4)