Posts

Showing posts with the label C# Tutorial

How to Convert JSON Object to XML in C#

Image
JSON (Javascript Object Notation) is very popular for web development. It is light weight data-exchange format. Most of the applications are using this format to exchange the data for web applications. Sample JSON array of Objects :  {    "users" : [       { "firstName" : "John" ,  "lastName" : "Peter" },       { "firstName" : "Wills" ,  "lastName" : "Smith" }     ] } To use this format, need to install the Newtonsoft.json package. For more detail and version related information you can find it ✋here . Open the Visual Studio, go to the package manager console and type the below command. Basic Definition of XML (Extensible Markup Language  is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. Sample XML format :  < root >    < user >         ...

Delete Empty Rows or Null Rows in Datatable in C#

How to Delete Empty Rows or Null Rows in Datatable Example:  In this application we can see how to Delete Empty Rows or Null Rows in Datatable. Mostly this issue comes from while uploading the excel(.xls,.xlsx) file data into your sql table through datatable in windows application or web application. In rare cases,we can see while getting data from excel to datatable it will copies the empty rows also. Below Code. C# public DataTable DeleteEmptyRowsFromDataTable(DataTable dt) { for (int i = dt.Rows.Count - 1; i >= 0; i--) { if (dt.Rows[i][1] == DBNull.Value) dt.Rows[i].Delete(); } dt.AcceptChanges(); return dt; }