title: How to display all Database data in Grid View using Data Table?
body: <p>I have 5 data in my datatbase, these data I want to display in a gridView using Data Table. But my code displays only the last binded data in GridView? My code is. Please point out the mistake?</p>
  
  <pre><code>SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
  SqlCommand cmd = new SqlCommand("select Date from MusterRoll where EmpCode='"+code+"' and Month='1' and Year='2015'", conn);
   SqlDataAdapter sda = new SqlDataAdapter(cmd);
   DataSet  ds = new DataSet();
   sda.Fill(ds);
   var rows = ds.Tables[0].Rows;
   foreach (DataRow row in rows)
    {
      string date1 = Convert.ToString(row["Date"]);
      DateTime date2 = Convert.ToDateTime(date1);
      SqlCommand cmd1 = new SqlCommand(" select TOP 1 m.EmpCode,m.NOH,m.OT,m.Late,m.Early,convert(varchar(10),m.Date,103)AS DATE,convert(varchar(10),s1.Shiftname,103)AS Shift From ShiftChange s,ShiftType s1,MusterRoll m  WHERE s1.ShiftID=s.NShiftID and '" + date2 + "'&gt;=Fromdate and Todate&gt;='" + date2 + "' and m.Month = '1' and m.date='"+date2+"' and m.EmpCode='Neena' order by Todate desc", conn);
      SqlDataAdapter sda1 = new SqlDataAdapter(cmd1);
      DataTable  dt = new DataTable();
      sda1.Fill(dt);
      //var rows1 = ds.Tables[0].Rows;
      for (int rowIndex = 0; rowIndex &lt; dt.Rows.Count; rowIndex++)
      {
        DataRow rpw = dt.Rows[rowIndex];
        string EmpCode = rpw.Field&lt;string&gt;("EmpCode");
        string NOH = rpw.Field&lt;string&gt;("NOH");
        string OT = rpw.Field&lt;string&gt;("OT");
        string Latae = rpw.Field&lt;string&gt;("Late");
        string Early = rpw.Field&lt;string&gt;("Early");
        string date3 =rpw.Field&lt;string&gt;("Date");
        string Shift = rpw.Field&lt;string&gt;("Shift");
        gvSingleemp.Visible = true;
        gvSingleemp.DataSource = dt;
        gvSingleemp.DataBind();
           }
          }
  </code></pre>
  
  <p>In my shiftChange table there is no Field for date instead of that I have fromDate and ToDate.I want display employee shifft according to MusterRoll table date. So that first I selected MusteRoll date nd checkrd this date exist in between ShiftChange FromDate and ToDate if exist show the Shift                           </p>