Skip to main content

How to Get JSON Data formate in Asp.net ???

Get JSON Data formate In Asp.net    (Without any third party libary file)           Steps 1: Nessary Namespace  __       using System.Web.Script.Serialization;        Steps 2: put the Folloing code__        [WebMethod]        public void getAllTheData()        {            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());            con.Open();            List<employee> emp = new List<employee>();            SqlCommand cmd = new SqlCommand("spgetData", con);            cmd.CommandType = CommandType.StoredProcedure;            using (SqlDataReader sdr = cmd.ExecuteReader())            {                while (sdr.Read())                {                    emp.Add(new employee                    {                        name = sdr["name"].ToString(),                        year = sdr["year"].ToString(),                        total =  Convert.ToInt32( sdr["total"].ToString())                    });                }            }            con.Close();            JavaScriptSerializer js = new JavaScriptSerializer();            Context.Response.Write(js.Serialize(emp));                     }        public class employee        {            public string name { get; set; }            public string year { get; set; }            public int total { get; set; }                               }   Description Here the class is employee ... Its is a example of consume data in a webmethod

Comments

Popular posts from this blog

How to get Reverse Of a number in C# ?

Reverse of a positive integer integer  number in c#  Program : using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Reverse {     class Program     {         static void Main( string [] args)         {             int num, rem, rev = 0;             Console .WriteLine( "//How to get Reverse of a number in c# ?" );             Console .WriteLine( "Enter A number :" );             num = Convert .ToInt32( Console .ReadLine());             if (num > 0)     ...

How to find sum of the digits of a number in c#?

Sum of the Digits of a number Program: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 {     class Program     {         static void Main( string [] args)         {             int num, sum = 0;             Console .WriteLine( "Enter a number :\n" );             num = Convert .ToInt32( Console .ReadLine());             if (num > 0)             {                 for ( int temp = num; tem...

How to check a number Prime or not in c# ?

/*Check a number Prime or not in C# */ Program : using  System; using  System.Collections.Generic; using  System.Linq; using  System.Text; using  System.Threading.Tasks; namespace  Primenumber {      class   Program     {          static   void  Main( string [] args)         {              int  num, flag = 0;              Console .WriteLine( "Enter A number :" );             num =  Convert .ToInt32( Console .ReadLine());              if  (num > 0)             {  ...