Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6217409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:25:19+00:00 2026-05-24T07:25:19+00:00

I want to access data and show in label ajax page methods but data

  • 0

I want to access data and show in label ajax page methods but data is not displaying.

PageMethods.GetDataFromDB(OnSucceeded, OnFailed);
         //}
        function OnSucceeded(result, userContext, methodName) {
            var jsonData = eval(result.d);
            $get('Label1').innerHTML = jsonData.FirstName;
        }    
 [WebMethod]
    public static string GetDataFromDB()
    {
        System.Collections.Generic.Dictionary<string, string> DictionaryGetPerson = new Dictionary<string, string>();
        using (OracleConnection con = new OracleConnection("server=xe; uid=system; pwd=;"))
        {
            string Command = "Select * from tblSavePerson";                //selecting Top 1 Row in Oracle
            OracleCommand cmd = new OracleCommand(Command, con);
            con.Open();
            OracleDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                DictionaryGetPerson.Add("FirstName",dr["FirstName"].ToString());

            }
        }
        JavaScriptSerializer js = new JavaScriptSerializer();
       return js.Serialize(DictionaryGetPerson).ToString();

}

table has only one row.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:25:20+00:00Added an answer on May 24, 2026 at 7:25 am

    Since you have given the tags as jQuery and jQuery Ajax I am deviating a little from the solution.

    Do these things

    1.Wrap your WebMethod in a try-catch block. try-catch are there for a reason.

    [WebMethod]
    public static string GetDataFromDB()
    {
        try
        {
            System.Collections.Generic.Dictionary<string, string> DictionaryGetPerson = new Dictionary<string, string>();
            using (OracleConnection con = new OracleConnection("server=xe; uid=system; pwd=;"))
            {
                string Command = "Select * from tblSavePerson";                //selecting Top 1 Row in Oracle
                OracleCommand cmd = new OracleCommand(Command, con);
                con.Open();
                OracleDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    DictionaryGetPerson.Add("FirstName", dr["FirstName"].ToString());
    
                }
            }
            JavaScriptSerializer js = new JavaScriptSerializer();
            return js.Serialize(DictionaryGetPerson).ToString();
        }
        catch (Exception exception)
        {
            //Elmah.ErrorSignal.FromCurrentContext().Raise(exception);
            throw new Exception(exception.Message);
        }
    }
    

    Please note that this Dictionary will fail with Duplicate Key error if you have more than one row. If there are no errors lets move to step 2.

    2.Do not use PageMethods.GetDataFromDB. It very ancient. Using jQuery one can consume ASP.NET Ajax Page Methods directly. Call Page method like this.

    function LoadNames() {
        $.ajax({
            contentType: "application/json;",
            data: "{}",
            type: "POST",
            url: 'Test1.aspx/GetDataFromDB',
            success: function (msg) {
                OnSucceeded(msg);
            },
            error: function (xhr, status, error) {
                //alert("error");
                //OnFailed(a, b, c);
            }
        });
    }
    
    function OnSucceeded(dict) {
        var jsonData = dict.hasOwnProperty("d") ? dict.d : dict;
        var json = $.parseJSON(jsonData);
        alert(json.FirstName);
    
    }
    

    Also, don’t eval(result.d) when we have $.parseJSON in jQuery.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using CGridView to show data in grid format, but i am not
I'm importing some XML to C#, and want to be able to access data
I want to access the value of a view controller data member variables in
I want to access a MySQL database and I want to read+write data from+to
I am writing some data access code and I want to check for potentially
I'm using Entity Framework for creation of my Data Access Layer and I want
I want to compare two ms-access .mdb files to check that the data they
I want to be able to access some device specific data while running an
I want to generate some formatted output of data retrieved from an MS-Access database
I want to convert the ms access data into a document so that the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.