Showing posts with label JSon. Show all posts
Showing posts with label JSon. Show all posts

Sunday, 5 February 2017

Convert DataGridview to DataTable with BindingSource By JSon


     Model.Sell sell = new Model.Sell();
     BindingSource bindingSource = new BindingSource();

        private void btnAdd_Click(object sender, EventArgs e)
        {
                sell.ID=1;
               sell.Name=tbxName.Text;
               bindingSource.Add(sell);
               BindData();

        }

       private void BindData()
       {
            DataGridView1.DataSource=bindingSource;
        }


        private DataTable ConvertToDataTable()
        {
                DataTable dt = new DataTable();
                string json = Newtonsoft.Json.JsonConvert.SerializeObject(bindingSource.List);
                dt = JsonConvert.DeserializeObject<DataTable>(json);          
               return dt;
        }

Thursday, 10 November 2016

How to convert list of model Data to DataTable in .Net

Convert List to DataTable is easy and light using JSon library.

Step 1: install Json library from Nuget package

>Go to Visual Studio Tools

> Library package manager > Package manager console

PM> Install-Package Newtonsoft.Json -Version 9.0.1

Your Model:
    public class Company : IEquatable<Company>
    {
        public int id { get; set; }

        public string name { get; set; }
               
        public string address { get; set; }
               
        public string phone { get; set; }

        public string fax { get; set; }
       
        public string email { get; set; }

        public string website { get; set; }
     }


private DataTable LoadCompany()
{
  private Company company;
  company = CompanyManager.getInstance().LoadCompanyList();
          
 string json = Newtonsoft.Json.JsonConvert.SerializeObject(company);
          
 var token = JToken.Parse(json);
          
 if (token.Type == JTokenType.Object)
          
     token = new JArray(token);
        
  DataTable dt = token.ToObject<DataTable>();
return dt;

}

Tuesday, 23 August 2016

Implement “WebAPI” in Asp.NET MVC

How to implement “WebAPI” in MVC?
Below are the steps to implement "webAPI" :-Step1:-Create the project using the "WebAPI" template.


Difference between WCF and WEB API


With WCF also you can implement REST,So why "WebAPI"?
WCF was brought in to implement SOA, never the intention was to implement REST."WebAPI'" is built
from scratch and the only goal is to create HTTP services using REST. Due to the one point focus for
creating “REST” service “WebAPI” is more preferred.

Comments system

Advertising

Disqus Shortname