为什么回发时间太长,无法从链接的服务器检索数据

问题描述 投票:0回答:1

我正在使用具有网格视图和内部网格视图的门户网站,我有两个文本框,其名称分别为txtEmployeeNumber和txtEmployeeName。而且我在txtEmployeeNumber上创建了一个事件text_changed,以便在回发第二个文本后将填充相应的数据,例如EmployeeName,请指导我在此方面进行哪些更改。我尝试了在源(链接服务器)上处理的OPENQUERY --,但无法正常工作。还有没有其他方法可以尽快检索数据。

我还分别在页面和UpdatePanel内部使用跟踪和触发器

Trace="true"

<Triggers> <asp:AsyncPostBackTrigger ControlID="txtEmployeeNumber" EventName="TextChanged" /> </Triggers>

在我的aspx页面中可以快速回发,但是没有发现任何变化

我的存储过程

CREATE procedure [dbo].[SP_Get_Employee_Name]  
 @Employee_ID nvarchar(max)  
AS  
BEGIN  

 DECLARE @emp_name nvarchar(max)  
 SELECT @emp_name = Employee_Name FROM [138.201.224.136].[iProfile].[dbo].[tbl_Employee]  
 WHERE Personnel_Number= @Employee_ID  

 IF (@emp_name is  null or @emp_name = '')  
 BEGIN  
  SELECT @emp_name = Name from [138.201.224.136].[iProfile].[dbo].[tbl_Contract_Employee]  
  WHERE [Unique id]= '110'+ @Employee_ID  
 END  

 SELECT @emp_name AS Employee_Name  
END

C#代码:

protected void txtEmployeeNumber_TextChanged(object sender, EventArgs e)
        {
            string EmployeeNo = "";
            foreach (GridViewRow row in grdRegister.Rows)
            {
                if (row.RowType != DataControlRowType.DataRow)
                    continue;

                EmployeeNo = (row.Cells[1].FindControl("txtEmployeeNumber") as TextBox).Text;

                SqlCommand cmd = new SqlCommand("SP_Get_Employee_Name", Con.OpenConnection());
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Employee_ID", EmployeeNo);
                Con.OpenConnection();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                if (dt.Rows.Count > 0)
                {
                    (row.Cells[2].FindControl("txtEmployeeName") as TextBox).Text = dt.Rows[0]["Employee_Name"].ToString();
                }
            }
        }
c# asp.net linked-server autopostback textchanged
1个回答
0
投票

不确定是否会有所不同,但是您确实需要更改某些点,以避免网络上无用的流量并减轻数据库的压力,这是>]

    protected void txtEmployeeNumber_TextChanged(object sender, EventArgs e)
    {
        string EmployeeNo = "";
        foreach (GridViewRow row in grdRegister.Rows)
        {
            // No point in executing the code below if we don't have a DataRow
            if (row.RowType != DataControlRowType.DataRow)
               continue;

            EmployeeNo = (row.Cells[1].FindControl("txtEmployeeNumber") as TextBox).Text;

            SqlCommand cmd = new SqlCommand("SP_Get_Employee_Name", Con.OpenConnection());
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@Employee_ID", EmployeeNo);

            // Also this line doesn't seem to be required. You have already
            // opened the connection in the command constructor above
            // Con.OpenConnection();

            // These are not needed at all
            // cmd.ExecuteNonQuery();
            // Con.CloseConnection(Con.OpenConnection());

            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                (row.Cells[2].FindControl("txtEmployeeName") as TextBox).Text = dt.Rows[0]["Employee_Name"].ToString();
            }
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.