karthik jogaian

karthik jogaian

  • NA
  • 6
  • 11.3k

Not displaying anything in Gridview

Oct 2 2014 10:56 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;

public partial class DispalyData : System.Web.UI.Page
{
    string strcon = ConfigurationManager.ConnectionStrings["TestConnectionString"].ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(strcon);
        
     
        SqlCommand cmd = new SqlCommand("Select * from ws_Students where DOB=@DOB", con);
        SqlParameter param = new SqlParameter("@DOB",DbType.DateTime);
        param.Value = DateTime.Now.ToString();
        cmd.Parameters.Add(param);
        con.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        con.Close();


    }
    
}


This is the code where I want to display ID, Name, Scholar from table ws_Students and also added DOB as parameter in a Gridview.  But error is not showing and gridview is not displayed in browser. Is there any thing to add in database or in cs file?
Please provide solution . Thanks in Advance. 

Answers (3)