Quote of the day

Monday, June 24, 2013

Datatable to json string in c#


I had a requirement to convert a datatable into json string. I saw couple of code samples in stackoverflow and code project, but I wanted to write of my own to make it simple. Below is the code


private static string DataTableToJSON(DataTable table)
    {
        string delimiter = string.Empty;
        string comma = string.Empty;
        StringBuilder json = new StringBuilder("[");
        foreach (DataRow row in table.Rows)
        {
            json.Append(delimiter);
            json.Append("{");
            foreach (DataColumn col in table.Columns)
            {
                json.Append(comma);
                json.Append("\"" + col.ColumnName + "\":\"" + row[col.ColumnName].ToString() + "\"");
                comma = ",";
            }
            json.Append("}");
            comma = string.Empty;
            delimiter = ",";
        }
        json.Append("]");
        return json.ToString();
    }

Same code is given as image below:



Monday, March 25, 2013

Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http]



I got the error

Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http].

sometime back and was google-ing for solution. Though the points and solutions which is mentioned for this issue was already setup in my machine, I still was getting the error. Then I found, there was a space after (,) comma in the "EnabledProtocols" under "Behavior" category in IIS -> myWebSite -> Advanced Settings for the net.tcp. Please refer to the below image


And we get the following error, when I try to execute the SVC file.

Later, I modified the protocol and removed the SPACE in the EnabledProtocols.


Below is the one which worked.

Online TFS

Microsoft provides TFS online. Here we can save the projects online. Now there may be no mandator requirement to have a dedicated server for saving the projects. Microsoft provides it online for FREE and it is for limited period.

                   This is something similar to GitHub, but not open source ;)

You can find more info here http://tfs.visualstudio.com/

You need to have a Windows Live ID to sign up for this.