Friday, February 26, 2010

View Profile Use of Data reader

 void displaympdetails()
    {

        conn.Open();
        string strQuery = "Select * from tbl_test where id='" + Request.Params.Get("id") + "'";
        cmd = new SqlCommand(strQuery, conn);
        dr = cmd.ExecuteReader();
        try
        {
            if (dr.Read())
            {
                lbldomain.Text = dr["domainname"].ToString();
                lblname.Text = dr["customername"].ToString();
                Session["customername"] = dr["customername"].ToString();
                lblconame.Text = dr["companyname"].ToString();
                lblmobile.Text = dr["contactno"].ToString();
            }
        }
        finally
        {
            conn.Close();
        }
        conn.Open();

        string strQuery1 = "Select * from tbl_customermaster where name='" + Session["customername"]+ "'";
        cmd = new SqlCommand(strQuery1, conn);
        dr = cmd.ExecuteReader();
        try
        {
            if (dr.Read())
            {
                lblphone.Text = dr["phone"].ToString();
                lbladdress.Text = dr["address"].ToString();
                lblemail.Text = dr["email"].ToString();
                lblbccemail.Text = dr["bccemail"].ToString();
                lblccemail.Text = dr["ccemail"].ToString();
            }
        }
        finally
        {
            conn.Close();
        }
    }