Hi
I'm creating a webservice which should get data from database(sql server) and return it.
Every thing working fine.But what i need is i need to display the data with the format which i need.
Here is my code:
public string GetEmployees()
{
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NSConstr"].ToString());
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT * FROM Contact e ";
DataSet ds = new DataSet();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand.Connection = con;
da.Fill(dt);
con.Close();
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row = null;
foreach (DataRow rs in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
row.Add(col.ColumnName, rs[col]);
}
rows.Add(row);
}
return serializer.Serialize(rows);
}
public string errmsg(Exception ex)
{
return "[['ERROR','" + ex.Message + "']]";
}
The result for the above code is:
[{"Id":1,"FirstName":"devi","LastName":"priya","Contactno":"965577796 "},{"Id":2,"FirstName":"arun","LastName":"kumar","Contactno":"9944142109"},
{"Id":3,"FirstName":"karu","LastName":"ronald","Contactno":"8883205008"}]
What i need is just the word {"cargo": and my result finally }
Here is the result which i expect
{ "Cargo": [{"Id":1,"FirstName":"devi","LastName":"priya","Contactno":"965577796 "},{"Id":2,"FirstName":"arun","LastName":"kumar","Contactno":"9944142109"},
{"Id":3,"FirstName":"karu","LastName":"ronald","Contactno":"8883205008"}]}
can any one please help me to solve this.
Thanks in advance.