Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey guys help me I cannot get the data in listview in android. I am using a c# webservice for retrieving the data from mssql server 2008R2 and this is my webservice:
C#
[WebMethod(Description = "Webservice for generating category wise report in JSON form")]
    public string getCategoryWiseReport(string district)
    {
        string dist = "23";
        district = dist;
        var con = new SqlConnection("data source=xxxxxx;initial catalog=xxxxxxx;integrated security=true");
        StringBuilder JSON = new StringBuilder();
        con.Open();
        var cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "ReportSummery";
        cmd.CommandType = CommandType.StoredProcedure;
        DataTable dt = new DataTable();
        SqlDataAdapter ad = new SqlDataAdapter(cmd);
        cmd.Parameters.AddWithValue("@district", district);
        cmd.ExecuteNonQuery();
        ad.Fill(dt);

        //string ofc_code=dt.Rows[0][0].ToString();
        //string ofc_desg = dt.Rows[0][1].ToString();
        //string ofc_name = dt.Rows[0][2].ToString();
        //string dep_name = dt.Rows[0][3].ToString();
        //string total_comp = dt.Rows[0][4].ToString();
        //string pending = dt.Rows[0][5].ToString();
        //string desposed = dt.Rows[0][6].ToString();
        //string interim = dt.Rows[0][7].ToString();
        //string defaulter = dt.Rows[0][8].ToString();
        JSON.Append("{");
        JSON.Append("\"Report\":[");
        for (int i = 0; i <= (dt.Rows.Count - 1); i++)
        {
            for (int j = 0; j <= 8; j++)
            {
                JSON.Append("{");
                JSON.Append("\"ofc_code\":\"" + dt.Rows[i][j].ToString() + "\", ");
                JSON.Append("\"ofc_desg\":\"" + dt.Rows[i][j].ToString() + "\", ");
                JSON.Append("\"ofc_name\":\"" + dt.Rows[i][j].ToString() + "\", ");
                JSON.Append("\"dep_name\":\"" + dt.Rows[i][j].ToString() + "\", ");
                JSON.Append("\"Total_complaint_recieved\":\"" + dt.Rows[i][j].ToString() + "\", ");
                JSON.Append("\"Total_complaint_disposed\":\"" + dt.Rows[i][j].ToString() + "\", ");
                JSON.Append("\"Total_complaint_pending\":\"" + dt.Rows[i][j].ToString() + "\", ");
                JSON.Append("\"Total_complaint_interim\":\"" + dt.Rows[i][j].ToString() + "\", ");
                JSON.Append("\"Total_complaint_default\":\"" + dt.Rows[i][j].ToString() + "\", ");
            }

            if (JSON.ToString().EndsWith(","))
            {
                JSON = JSON.Remove(JSON.Length - 1, 1);
            }

            JSON.Append("]}");
        }
        con.Close();
        return JSON.ToString();
        //string s=ofc_code+","+ofc_desg+","+ofc_name+","+dep_name+","+total_comp+","+pending+","+desposed+","+interim+","+defaulter;
        //return s;

    }


And this webservice is retrieving the data from the sqlserver stored procedure. I want to know how can i retrieve this json data in android such that I can fill a listview with it.
Posted
Updated 3-Sep-14 8:40am
v2
Comments
Nathan Minier 3-Sep-14 14:00pm    
Not sure what you're asking here. Are you using a framework, do you have an SPA that's touching the service, are you going cross-domain from another web-page provider, is a Java app querying the data...

Without knowing anything about your UI endpoint, I'm not sure how anyone can advise you on what to do on the UI endpoint.
dushyant99 3-Sep-14 14:14pm    
the webservice is created in .net framework 3.5 and I want to retrieve this json data in a listview in android. for android i am using eclipse adt and version of android is jellybeans 4.2
Nathan Minier 3-Sep-14 14:26pm    
Okay, that's explicitly a Java endpoint then.

I apologize for any confusion; a ListView is also an element used in ASP.NET, and android could mean app, browser, etc, which is why I wanted to be sure.

You should edit your question tags from C# to Java for better help.

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