Click here to Skip to main content
15,886,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I Want to return Json Webservice From Sql Server in Asp.net Using C# I Want. Especially I want Selecting Querry

This Is Return Webservice:
JavaScript
{ "Cargo": [ { "status": "pickup", "datetime": "" }, { "status": "InTransit",

"datetime": "" }, { "status": "ReachedBLR", "datetime": "" }, { "status":

"StartedDEL", "datetime": "" }, { "status": "InTransit", "datetime": "" }, { "status": "ReachedDEL", "datetime": "" }] }..


Please help me by giving code
Thanks In advance..
Posted
Updated 1-Apr-14 4:41am
v4
Comments
Sergey Alexandrovich Kryukov 1-Apr-14 8:49am    
What does it mean, "return a service"? :-)
—SA
Member 10556609 1-Apr-14 9:22am    
Sorry Sir Now I Changed..
joshrduncan2012 1-Apr-14 9:26am    
Please reply to comment instead of creating a new comment, otherwise, the person will not get notified that you responded.
Member 10556609 1-Apr-14 9:31am    
i Want to Create JSON Webservice In Asp.Net USing C# .The data will Get From SQl Server. I want webService Response LIke This.
{ "Cargo": [ { "status": "pickup", "datetime": "" }, { "status": "InTransit",

"datetime": "" }, { "status": "ReachedBLR", "datetime": "" }, { "status":

"StartedDEL", "datetime": "" }, { "status": "InTransit", "datetime": "" }, { "status": "ReachedDEL", "datetime": "" }] }..
ZurdoDev 1-Apr-14 9:26am    
What is your question?

Hello,

Here is a simple trick to get the answer. Click here[^].

Still can't get then have a look at this[^].

Regards,
 
Share this answer
 
[WebMethod]
public static string GetDistrictByRegionID(string regionID)
{
string jsonString = string.Empty;
try
{
DealerSalesBO objDealerSalesBO = new DealerSalesBO();
DataSet ds = objDealerSalesBO.GetDistrictByRegionID(companyId, regionID);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
jsonString = JsonHelper.GetJson(ds.Tables[0]);
}
}
catch (Exception ex)
{
jsonString = "[{\"ErrorMessage\":\"" + ex.Message + "\"}]";
}

return jsonString;
}

public class DealerSalesBO
{
string KIAS_ConnectionString = ConfigurationManager.ConnectionStrings["KIAS_ConnectionString"].ConnectionString;

public DealerSalesBO()
{

}

public DataSet GetDistrictByRegionID(int companyID, string regionID)
{
DataSet objDS = null;
try
{
objDS = new DataSet();
string spName = "sps_DistrictRpt";

SqlParameter[] arParms = new SqlParameter[2];
arParms[0] = new SqlParameter("@Company_ID", SqlDbType.Int);
arParms[0].Value = companyID;

arParms[1] = new SqlParameter("@RegionID", SqlDbType.VarChar);
arParms[1].Value = regionID;

SqlHelper.FillDataset(KIAS_ConnectionString, CommandType.StoredProcedure, spName, objDS, new string[] { "T_DistrictMST" }, arParms);
}
catch (Exception ex)
{
throw ex;
}

return objDS;
}
}

public static class JsonHelper
{
public static string GetJson(DataTable dt)
{
string jsonString = string.Empty;
try
{
if (dt == null)
{
throw new Exception("DataTable is null...");
}

JavaScriptSerializer serializer = new JavaScriptSerializer();
ArrayList lstArrayList = new ArrayList();
foreach (DataRow dr in dt.Rows)
{
Dictionary<string,> objDictionary = new Dictionary<string,>();
foreach (DataColumn col in dt.Columns)
{
objDictionary.Add(col.ColumnName.Trim(), dr[col]);
}

lstArrayList.Add(objDictionary);
}

jsonString = serializer.Serialize(lstArrayList);
}
catch (Exception ex)
{
throw ex;
}
return jsonString;
}

}
 
Share this answer
 
Please do not repost - see answers here:I Want to return JSON webservice using Asp.net c#[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900