0 votes
524 views
in Programming by (2.1k points)

i am using this code to get database and convert it into JSON and display in android through web services.

public string Method()
{
        DataTable dt = new DataTable();
        using (SqlConnection con = new SqlConnection(@"Connection_string"))
        {
            using (SqlCommand cmd = new SqlCommand("_query_", con))
            {
  con.Open();
  SqlDataAdapter da = new SqlDataAdapter(cmd);
  da.Fill(dt);
  System.Web.Script.Serialization.JavaScriptSerializer serializer 
            = new System.Web.Script.Serialization.JavaScriptSerializer();
   List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
                Dictionary<string, object> row;
                foreach (DataRow dr in dt.Rows)
                {
                    row = new Dictionary<string, object>();
                    foreach (DataColumn col in dt.Columns)
                    {
                        row.Add(col.ColumnName, dr[col]);
                    }
                    rows.Add(row);
                }
                return serializer.Serialize(rows);
            }
        }
}

In the same way if an android app gives a data then how would I be able to get that data and insert it into database?

Your answer

Thanks for contributing your answer!
Please be sure to answer the question. Provide details with examples and share your research!
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated