Gridview Examples with Sql Server Database in asp.net

Gridview Examples with Sql Server Database in asp.net

Example-1(SqlDataAdapter example in asp.net)

using System;         
using System.Collections.Generic;
using System.Linq;    
using System.Web;
using System.Web.UI;   
using System.Web.UI.WebControls;
using System.Data;     
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
    protected voidPage_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GriviewShow();
        }
     }
     void GriviewShow()
    {
        SqlConnection con = newSqlConnection(@"Data Source=ITIKA-PC\SQLEXPRESS;Initial Catalog=Simple;Integrated Security=True");
        SqlDataAdapter da = newSqlDataAdapter("Select *from ProductTable", con);
        DataSet ds = new DataSet();      
        da.Fill(ds);
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();
    }
  }




protected voidSearchButton1_Click(object sender, EventArgs e)
     {
SqlConnection con = newSqlConnection(@"Data Source=ITIKA-PC\SQLEXPRESS;Initial Catalog=Simple;Integrated Security=True");
SqlDataAdapter da = newSqlDataAdapter("Select *from ProductTable where ProductId="+TextBox1.Text, con);
         DataSet ds = new DataSet();
         da.Fill(ds);
         GridView1.DataSource = ds.Tables[0];
         GridView1.DataBind();     
    }

Comments

Popular posts from this blog

Creating a DDL File & link ddl file in C#

SQL Command in asp.net