Ajith s

Ajith s

  • NA
  • 9
  • 8.2k

regarding gridview in asp.net

Dec 8 2012 8:25 AM
hi i got error in coding of grid view in asp.net
here is my coding


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Data;


namespace adapter
{
    public partial class _Default : System.Web.UI.Page
    {
        public SqlConnection con = new SqlConnection();
        public SqlCommand cmd = new SqlCommand();
        public SqlDataAdapter sda = new SqlDataAdapter();
        public SqlDataReader sdr;
        public DataTable myDataTable = new DataTable();
        public String constr, cmdstr;
        protected void Page_Load(object sender, EventArgs e)
        {
            constr = @"Data Source=RAHUL-PC\SQLEXPRESS;Initial Catalog=a1;Integrated Security=True";
            con = new SqlConnection(constr); 
            

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            con.Open();
                cmd=new SqlCommand("select * from details",con);
            sda=new SqlDataAdapter(cmd);
            sda.Fill(myDataTable);
            GridView2.DataSource = myDataTable;
            GridView2.DataBind();
            con.Close();

        }

        
    }
}

Answers (2)