0

我有以下服务器代码:

方法.cs

public DataTable GetAllCreditCards()
        {
            string connStr = ConfigurationManager.ConnectionStrings["BankDB"].ConnectionString;
            SqlConnection conn = new SqlConnection(connStr);
            SqlDataAdapter adapter = new SqlDataAdapter();
            DataTable data_table = new DataTable();
            conn.Open();

            SqlCommand cmd = new SqlCommand("GetAllAccountDetails", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            adapter.SelectCommand = cmd;
            adapter.Fill(data_table);
            conn.Close();
            return data_table;
        }

处理程序.ashx

if (function.Equals("GetAllCreditCards"))
            {
                DataTable text = m.GetAllCreditCards();

                System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                string json = oSerializer.Serialize(text);

                context.Response.Write(json);
            }

我有以下客户端代码:

主页.aspx

if (TextBox_Function.Text.Equals("GetAllCreditCards"))
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:4000/Handler.ashx?function=" + TextBox_Function.Text);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                String answer = returnResponse(response);

                System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                DataTable data_table = oSerializer.Deserialize<DataTable>(answer);

                Session["data_table"] = data_table;
                Response.Redirect("Results_Reader.aspx");
            }

Results_Reader.aspx

protected void Page_Load(object sender, EventArgs e)
{
    DataTable data_table = (DataTable)Session["data_table"];
    GridView_DataTable.DataSource = data_table;
    GridView_DataTable.DataBind();
}

我要做的是从服务器获取数据库数据,将其放入数据表中,将数据表发送到客户端并将该数据表绑定到网格视图。

当我尝试运行客户端并在变量函数中输入“GetAllCreditCards”时,服务器项目出现以下错误:

A circular reference was detected while serializing an object of type 'System.Reflection.RuntimeModule'.

我究竟做错了什么?我只想传递数据库数据并将其绑定到客户端的网格视图,仅此而已。

编辑

JavaScriptSerializer 似乎无法序列化数据表。那么如何将记录从服务器发送到客户端并将它们绑定到网格视图?

4

1 回答 1

1

我的猜测是您正在执行的 javascript 序列化存在问题,如果这有帮助,请查看此处序列化“SubSonic.Schema .DatabaseColumn”类型的对象时检测到循环引用。

于 2013-04-15T15:55:04.527 回答