使用循环我正在显示记录 [英] Using loop I am displaying record

查看:91
本文介绍了使用循环我正在显示记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在表格记录中如下





In table record as follows


CourseCode    CoruseName     Studentid    City
   RM          Remunration     45555        1
   REO         Revalidation    88787        1
   CTF         Tanker          98889        1
   ECDIS       Practical       88877        1
   AMOS        Manual          78798        1
   DFC         Familarazation  87899        2







i显示以上数据进入Gridview。代码如下






i am displaying the above data in to Gridview. code as follows

string Con= "Server=(local);initial catalog=Testing;Trusted_Connection=True";
SqlConnection sqlcon= new SqlConnection(Con);
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
cmd.CommandText = "select * from Course";
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlcon;
             sqlcon.Open();
             dr= cmd.ExecuteReader();
             if (dr.HasRows)
             {
                 if (reader.Read())
                 {
                     string City = dr[6].ToString();
                     if (City== "1") ;
                    {
                      Griview.Datasource = dr;
                      Gridview.databind();
                    }
                  }
             }











i我在检查城市1是否意味着。那个城市1所有记录都要在gridview中显示。



当我在Gridview输出中执行上面的代码时如下








i am checking if City 1 means. that city 1 all record to be displayed in gridview.

When i execute the above code in Gridview Output as follows

CourseCode    CoruseName     Studentid    City

  RM          Remunration     45555        1





在上面的gridview中只显示第一条记录。但并非表格中的所有记录都没有显示。





但是我希望Gridview中的输出如下







in the above gridview only first record only displayed. But not all the records in table is not displaying.


But i want the output in Gridview as follows


CourseCode    CoruseName     Studentid    City
    RM          Remunration     45555        1
    REO         Revalidation    88787        1
    CTF         Tanker          98889        1
    ECDIS       Practical       88877        1
    AMOS        Manual          78798        1





请帮我解决我的代码中的问题



please help me what is the problem in my code

推荐答案

试用此代码获取所需数据:



Try this code to get required data:

string Con= "Server=(local);initial catalog=Testing;Trusted_Connection=True";
SqlConnection sqlcon= new SqlConnection(Con);
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
cmd.CommandText = "select * from Course where City=1";
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlcon;
             sqlcon.Open();
             dr= cmd.ExecuteReader();
             if (dr.HasRows)
             {
                 if (reader.Read())
                 {  
                    Griview.Datasource = dr;
                    Gridview.databind();
                    
                  }
             }


这篇关于使用循环我正在显示记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆