我在c#中有一個web服務,它以datatable的形式返回數據,我想訪問數據表dt中有110行的元素, 8列如何檢索我的android應用程序中的每個行值並將其顯示在表中。幫我請:在Android應用程序中從asp.net webservice類型數據表中檢索元素
這是我的web服務:
[WebMethod(Description = "Webservice for generating category wise report")]
public DataTable getCategoryWiseReport(string district)
{
var con = new SqlConnection("data source=(local);initial catalog=xxxx;integrated security=true");
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();
for (int i = 0; i <= (dt.Rows.Count-1); i++)
{
for (int j = 0; j <= 8; j++)
{
dt.Rows[i][j].ToString();
}
}
con.Close();
return dt;
//string s=ofc_code+","+ofc_desg+","+ofc_name+","+dep_name+","+total_comp+","+pending+","+desposed+","+interim+","+defaulter;
//return s;
}
你有沒有考慮使用一些ORM並將數據映射到對象數組? – 2014-08-28 09:01:40
不,我不。如何做到這一點...... – user3469177 2014-08-28 09:10:42
試試這個:http://stackoverflow.com/questions/19650503/get-array-item-from-webservice-object-to-android/19653152#19653152 – Dhaval 2014-08-28 09:19:12