Sample Code For DataBase Connection Using Asp.net

        protected void Page_Load(object sender, EventArgs e)
        {
             SqlCommand MyCommand;  
            SqlDataAdapter MyAdapter;  
            DataTable MyTable;
            SqlConnection MyConnection;
            MyConnection = new SqlConnection();
            MyConnection.ConnectionString = "Data Source=B406DCOK;Initial  Catalog=Akhil;Integrated Security=True";  

            MyCommand = new SqlCommand();  
            MyCommand.CommandText = "select * from Table_3";  
            MyCommand.CommandType = CommandType.Text;  
            MyCommand.Connection = MyConnection;
          
           
            MyTable = new DataTable();  
            MyAdapter = new SqlDataAdapter();  
            MyAdapter.SelectCommand = MyCommand;  
            MyAdapter.Fill(MyTable);  
  
            GridView1.DataSource = MyTable.DefaultView;  
            GridView1.DataBind();  
      }

Comments

Popular posts from this blog

Introduction To Oracle10g

Insert

Except