【发布时间】:2010-01-25 06:24:37
【问题描述】:
我正在使用 Webservice,它将通过数据表从数据库中返回数据,并将数据表转换为字节数组。在前端,我将 bytearray 重新转换为 datatable 并使用 ajaxloader 将其显示在表单中。它是动态加载。因此,对于每次点击,无论数据大小如何,都需要 10 秒来检索数据。所以,我使用了静态数据表,并在页面加载事件中加载了该数据表中的所有数据。但是,没有反应。它只需要同样的时间。甚至,没有要检索的数据,ajax 加载器正在加载 10 秒。问题出在 Ajax 或我的 Web 服务上??请告诉我一些其他的想法??!!
我的 listboxclick 事件代码
protected void listboxcity_SelectedIndexChanged(object sender, EventArgs e)
{
string sqlvalue = string.Empty;
//Thread.Sleep(200);
for (int i = 0; i < listboxcity.Items.Count; i++)
{
if (listboxcity.Items[i].Selected == true)
sqlvalue += listboxcity.Items[i].ToString() + ",";
}
if (sqlvalue.EndsWith(","))
{
sqlvalue = sqlvalue.Remove(sqlvalue.Length - 1);
}
txtprefcity.Text = sqlvalue;
if (txtprefcity.Text != string.Empty)
{
listboxarea.Items.Clear();
txtprefarea.Text = "";
try{
string[] strarea = txtprefcity.Text.ToString().Split(',');
foreach (String s in strarea)
{
DataTable dtarea = new DataTable();
DataTable dt = bc.ConvertByteToDataTable(objservice.GetData("getdistrictbyname", new object[] { s }));
foreach (DataRow r in dt.Rows)
dtarea = bc.ConvertByteToDataTable(objservice.GetData("getarea", new object[] { int.Parse(r["countryid"].ToString()), int.Parse(r["stateid"].ToString()), int.Parse(r["districtid"].ToString()) }));
foreach (DataRow rw in dtarea.Rows)
{
listboxarea.Items.Add(rw["areaname"].ToString());
}
}
}
catch (Exception ex)
{
ObjLog.Write(ex.Message);
}
}
}
网页方法如下:
public byte[] GetData(string StoredProcedureName, params object[] ParameterValues)
{
GC.Collect();
using (SqlConnection MyConnection = new SqlConnection(connectionstring))
{
using (SqlCommand MyCommand = new SqlCommand(StoredProcedureName, MyConnection))
{
using (SqlDataAdapter MyAdapter = new SqlDataAdapter())
{
MyConnection.Open();
MyCommand.CommandType = CommandType.StoredProcedure;
MyAdapter.SelectCommand = MyCommand;
SqlCommandBuilder.DeriveParameters(MyCommand);
int Index = 0;
foreach (SqlParameter Parameter in MyCommand.Parameters)
{
if (Parameter.Direction == ParameterDirection.Input || Parameter.Direction == ParameterDirection.InputOutput)
{
if (ParameterValues[Index] != null)
{
if (ParameterValues[Index].ToString() != string.Empty)
{
Parameter.Value = ParameterValues[Index];
}
else
{
Parameter.Value = DBNull.Value;
}
}
else
{
Parameter.Value = DBNull.Value;
}
Index++;
}
}
using (DataTable ds = new DataTable())
{
MyAdapter.Fill(ds);
MyConnection.Close();
return convertdatatabletobytearray(ds);
}
}
}
}
}
【问题讨论】:
标签: c# asp.net ajax web-services