예제 #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         DataTable dt = DBLogic.FetchAllRecord();
         DropDownList1.DataSource     = dt;
         DropDownList1.DataTextField  = "userid";
         DropDownList1.DataValueField = "userid";
         DropDownList1.DataBind();
     }
 }
예제 #2
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataTable dt = DBLogic.FetchAllRecord();

        GridView1.DataSource = dt;
        GridView1.DataBind();

        /*  SqlConnection con = null;
         * try
         * {
         *    con = DBLogic.GetConnection();
         *
         *    String query = "select * from reg ";
         *
         *    //create the SqlDataAdapter object
         *    SqlDataAdapter da = new SqlDataAdapter(query, con);
         *
         *    //create the object Dataset
         *    DataSet ds = new DataSet();
         *
         *    //Call the fill Method and pass the
         *    //DataSet object
         *    da.Fill(ds);
         *
         *    //get the no of tables dataset contains
         *    DataTable dt = ds.Tables[0];
         *
         *    //bind the dataset table with the GridView
         *    GridView1.DataSource = dt;
         *    GridView1.DataBind();
         * }
         * catch (Exception err)
         * {
         *    Label1.Text = err.Message;
         * }
         * finally
         * {
         *    if (con != null)
         *    {
         *        con.Close();
         *    }
         * }*/
    }
예제 #3
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = null;

        try
        {
            con = DBLogic.FetchAllRecord();

            con.Open();
            //build a query
            String     query = "delete from reg where userid ='" + txtuserid.Text + "'";
            SqlCommand com   = new SqlCommand(query, con);

            //call the method of command object
            int result = com.ExecuteNonQuery();

            if (result > 0)
            {
                Label2.Text = "Record DELETED successfully";
            }
            else
            {
                Label2.Text = "NO Record FOUND";
            }
        }
        catch (Exception err)
        {
            Label2.Text = err.Message;
        }
        finally
        {
            if (con != null)
            {
                con.Close();
            }
        }
    }