@Override
protected String doInBackground(String... params)
{
String s="";
for( int i=1;i< Amount_1.length;i++) {
String jsonurl = "http://rsk.abc.com/WebService1.asmx/Insert";
date = null;
try {
amount[0]= "10000";
name[0]= "jack";
amount[1]= "100000";
name[1]= "harris";
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(jsonurl);
List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("name", name[i]));
list.add(new BasicNameValuePair("amount", amount[i]));
httpPost.setEntity(new UrlEncodedFormEntity(list));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
// s= readResponse(httpResponse);
s = getJSONString(httpResponse);
} catch (Exception exception) {
String err = exception.getMessage().toString();
return err;
}
}
return s;
}
}
[WebMethod(Description = "Transaction")]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string Insert(
string[] name,
string[] amount,
)
{
string msg = "";
SqlCommand[] cmd3= new SqlCommand[10];
SqlTransaction trans = null;
con.Open();
string a = Insert_firsttable(name[0],amount[1]);
string b=Insert_secondtable(name[1],amount[1]);
cmd3[0] = new SqlCommand(a, con);
cmd3[1]= new SqlCommand(b, con);
trans = con.BeginTransaction();
cmd3[0].Transaction = trans;
cmd3[1].Transaction = trans;
}
try
{
for (int j = 0; j < 2; j++)
{
cmd3[j].ExecuteNonQuery();
}
trans.Commit();
trans = null;
msg = "success";
return msg;
}
catch (Exception)
{
msg = "oooops";
if (trans != null)
{
trans.Rollback();
trans = null;
msg = "oops";
}
return msg;
}
finally
{
con.Close();
}
}
我能够将参数作为字符串传递。但不能作为数组参数。我不知道如何传递数组作为参数。我需要在webmethod.so中插入事务内的两个表,我需要将参数作为数组传递。