Monday, June 2, 2014

How to convert List to Datatable in vb.net

Public Function ConvertToDataTable(Of T)(ByVal list As IList(Of T)) As DataTable
        Dim table As New DataTable()
        Dim fields() As FieldInfo = GetType(T).GetFields()
        For Each field As FieldInfo In fields
            table.Columns.Add(field.Name, field.FieldType)
        Next
        For Each item As T In list
            Dim row As DataRow = table.NewRow()
            For Each field As FieldInfo In fields
                row(field.Name) = field.GetValue(item)
            Next
            table.Rows.Add(row)
        Next
        Return table
    End Function

Thursday, April 17, 2014

How to parse json string to dataset in C#

// Serialization of DataSet to json string
StringWriter sw = new StringWriter();
versionUpGetData.WriteXml(sw, XmlWriteMode.WriteSchema);
XmlDocument xd = new XmlDocument();
xd.LoadXml(sw.ToString());
String jsonText = JsonConvert.SerializeXmlNode(xd);
File.WriteAllText(“d:/datasetJson.txt”,jsonText);

//Deserialization of Json String to DataSet
XmlDocument xd1 = new XmlDocument();
xd1 = (XmlDocument)JsonConvert.DeserializeXmlNode(jsonText);
DataSet jsonDataSet = new DataSet();
jsonDataSet.ReadXml(new XmlNodeReader(xd1));

Monday, February 10, 2014

What is final class in Object Oriented Programming

Final Class: A class that is defined as final class can not be inherited further. All Methods of a final class are inherently final and must not be declared as final in the class definition. Also, a final method can not be redefined further.
If only a method of a class is final then that class can be inherited but that method cannot be redefined.