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
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
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
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