2
Reply

Displaying the database record in to Gridview using conditio

narasiman rao

narasiman rao

Aug 15 2016 7:52 AM
272
  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 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 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

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
 

Answers (2)