2 Replies - 2006 Views - Last Post: 04 April 2012 - 04:42 AM Rate Topic: -----

#1 ankit9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 18-February 11

Not able to display data with label control

Posted 04 April 2012 - 01:54 AM

hi!! i need to display data from database into a label control, but no datais displaying.... i don't know what the problem is

below is the code....

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using memberdll;

public partial class account_profile : System.Web.UI.Page
{

    public void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {

            SqlConnection con = new SqlConnection("my connectionstring name");

            SqlCommand cmd = new SqlCommand("SELECT username,u_fname,u_lname,u_password,u_email_id FROM users_detail", con);
          
            try
            {

                con.Open();

                SqlDataReader reader = cmd.ExecuteReader();


                DataSet ds = new DataSet();

                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(ds);



                while (reader.Read())
                {

                    ////Label mem_username = new Label();
                    //Label mem_fname = new Label();
                    //Label mem_lname = new Label();
                    //Label mem_pass = new Label();
                    //Label mem_email_id = new Label();


                    //string u = reader.GetValue(0).ToString();
                    //string fn = reader.GetValue(0).ToString();
                    //string ln = reader.GetValue(0).ToString();
                    //string pass = reader.GetValue(0).ToString();
                    //string email = reader.GetValue(0).ToString();

                    DataTable dt = new DataTable();



                    mem_username.Text = dt.Rows[0]["username"].ToString();
                    mem_lname.Text = dt.Rows[0]["u_fname"].ToString();
                    mem_pass.Text = dt.Rows[0]["u_lname"].ToString();
                    mem_email_id.Text = dt.Rows[0]["u_email_id"].ToString();

                    reader.Close();
                }


            }

            catch (SqlException ex)
            {

                con.Close();

                Label messbox = new Label();

                string a = "Sorry!! an Error Occured : " + ex.Message;
                messbox.Text = a;

            }

            try
            {
                SqlCommand cmd1 = new SqlCommand("SELECT u_sec_qst,u_sec_ans FROM u_security", con);


                con.Open();
                SqlDataReader reader1 = cmd1.ExecuteReader();


                while (reader1.Read())
                {
                    //Label mem_sec_qst = new Label();
                    //Label mem_sec_ans = new Label();

             
                    SqlDataReader reader = cmd1.ExecuteReader();


                    DataSet ds = new DataSet();

                    SqlDataAdapter da = new SqlDataAdapter(cmd1);
                    da.Fill(ds);



                    DataTable dt = new DataTable();

                    mem_sec_qst.Text = dt.Rows[0]["username"].ToString();
                    mem_sec_ans.Text = dt.Rows[0]["username"].ToString();


                    reader1.Close();
                }
            }

            catch (SqlException ex1)
            {
                Label messbox1 = new Label();


                con.Close();

                string a = "Error : " + ex1.Message;
                messbox1.Text = a;


            }
        }

        else
        {
        
        errorsss.Text = "errors";
        }
    }
}


these data are of member's detail's and i need to display on page load..... but it's not displaying any data

can someone please help me...

Thank's in advance..

This post has been edited by Dormilich: 04 April 2012 - 01:55 AM
Reason for edit:: please use [code] [/code] tags when posting code


Is This A Good Question/Topic? 0
  • +

Replies To: Not able to display data with label control

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: Not able to display data with label control

Posted 04 April 2012 - 02:35 AM

* Moved to the ASP.NET forum *
Was This Post Helpful? 0
  • +
  • -

#3 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 444
  • View blog
  • Posts: 1,492
  • Joined: 28-April 09

Re: Not able to display data with label control

Posted 04 April 2012 - 04:42 AM

are you getting any errors? Have you stepped through your code using the debugger to see what it's doing?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1