Kavi suja

Kavi suja

  • NA
  • 298
  • 171.2k

OOPS concept - Gridview Data Bind

Jul 23 2013 7:23 AM
Hi,
   I have register page and view page.In Register page I insert data in to database.In view page,all the data entered in Register page will be shown in Grid.I use Stored procedure for this.Now I've to done this task using anyone of oops concept.But i don't know so much about oops concept.How I use oops concept here?Can anyone help me to do this?
I include my code here:
protected void Page_Load(object sender, EventArgs e)
    {
        con = new MySqlConnection("server=localhost;User Id=root;database=userdata;password=MySqlAdmin");
        con.Open();
        if (!IsPostBack)
        {                 
            BindGridView();
        }
    }

    


    private void BindGridView()
    {
        using (MySqlConnection con = new MySqlConnection("server=localhost;User Id=root;database=userdata;password=MySqlAdmin"))
        {
            DataSet ds = new DataSet();
            MySqlCommand cmd = new MySqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "viewdata";
            cmd.Connection = con;
            try
            {
                con.Open();
                gvcontact.EmptyDataText = "No Records Found";
                gvcontact.DataSource = cmd.ExecuteReader();
                gvcontact.DataBind();
            }
            catch (Exception ex)
            {
                throw ex;
            }
                finally
                {
                    con.Close();
                    con.Dispose();
                }








Answers (5)