-->

Monday, June 24, 2013

How to use HasRows property of SqlDataReader class

How to use HasRows property of SqlDataReader class

Use HasRows property of SqlDataReader class 
Gets a value that indicates whether the SqlDataReader contains one or more rows (msdn.microsoft.com)



Step-1 : Create a database table with empty data


empty data




Step-2 : Check data in database using HasRows property of  SqlDataReader class

Step-3 :  Write code on page_load method



using System;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public partial class duplicatevalue : System.Web.UI.Page
{
    SqlDataReader rd;

    protected void Page_Load(object sender, EventArgs e)
    {

        using (SqlConnection con = new SqlConnection())
        {
            con.ConnectionString =ConfigurationManager .ConnectionStrings ["ConnectionString"].ToString ();
            con.Open();
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.CommandText = "checkdata";
                cmd.Connection = con;
                cmd.CommandType = CommandType.StoredProcedure;
                rd = cmd.ExecuteReader();
                if (rd.HasRows)
                {
                   result.Text="Row Exisit";  //here result is the id of the label control
                }
                else
                {
                    result.Text = "no row found";

                  
                }
                                
            }

       
        }

    }

OutPut Screen
EmptyData





Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved