Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在asp.net中使用datalist控件显示SQL Server数据库的结果会占用时间_C#_Asp.net_Sql Server - Fatal编程技术网

C# 在asp.net中使用datalist控件显示SQL Server数据库的结果会占用时间

C# 在asp.net中使用datalist控件显示SQL Server数据库的结果会占用时间,c#,asp.net,sql-server,C#,Asp.net,Sql Server,我有3个单选按钮业务、联系人、地址 三个数据列表: 业务:显示公司名称、员工姓名、电子邮件ID、联系人、网站地址 联系人:显示员工姓名、联系人 地址:EmaiID,公司名称,网址 在检查单选按钮时,我显示相应的数据列表 对于DataList业务,我有>1000行的记录,当我选中单选按钮时,显示结果需要时间 我应该怎么做才能使我的应用程序平稳快速地运行?我正在使用字母分页来按字母顺序显示数据列表结果。我希望一次显示1000条以上的记录,可能记录数大于或等于5000条 这是我的存储过程: if(@t

我有3个单选按钮业务、联系人、地址

三个数据列表:

业务:显示公司名称、员工姓名、电子邮件ID、联系人、网站地址

联系人:显示员工姓名、联系人

地址:EmaiID,公司名称,网址

在检查单选按钮时,我显示相应的数据列表

对于DataList业务,我有>1000行的记录,当我选中单选按钮时,显示结果需要时间

我应该怎么做才能使我的应用程序平稳快速地运行?我正在使用字母分页来按字母顺序显示数据列表结果。我希望一次显示1000条以上的记录,可能记录数大于或等于5000条

这是我的存储过程:

if(@type = 'Business')
begin
    if(@Utype  ='1' )
    begin
        IF (@Alphabet = 'A' and @name = '' and @company = '' ) 
        BEGIN
           SELECT  
               Company, Address, CardDetail.Name, Email, Mobile, Telephone, Fax, Web, Job, 1, createdby
           FROM 
               CardDetail   
           WHERE 
               Company LIKE 'A%' 
               AND (ViewType = 'C' OR ViewType = 'A' OR createdby = @uid) 
        END

        IF (@Alphabet <> 'A' AND @name = '' AND @company = '') 
        BEGIN
            SELECT  
               Company, Address, Name, Email, Mobile, Telephone, Fax, Web, Job, 2, createdby
            FROM 
               CardDetail  
            WHERE 
               Company LIKE @Alphabet + '%' 
               AND (ViewType = 'C' OR ViewType = 'A' OR createdby = @uid) 
            ORDER BY
               Company ASC
        END

        IF (@name <> '' and @company <> '')
        begin
           SELECT DISTINCT 
              Company, Address, Name, Email, Mobile, Telephone, Fax, Web, Job, 3, createdby 
           FROM 
              CardDetail  
           WHERE 
              Company = @company 
              AND Name = @name  
              AND (ViewType = 'C' OR ViewType = 'A' OR createdby = @uid) 
           ORDER BY 
              Company ASC
end
页面加载

     protected void Page_Load(object sender, EventArgs e)
    {

                Business.Visible = false;
                Address.Visible = false;
                Contact.Visible = false;
                dl_company.Visible = false; 
                ViewState["CurrentAlphabet"] = "A";
                this.GenerateAlphabets();
     }     

是不是查询太慢了?还是实际的Web UI?C代码?您应该从分析SQL开始,通过SSMS查看查询需要多长时间。开始时间:2014-10-25 14:04:13.960结束时间:2014-10-25 14:04:13.973总计:13ms
     private void BindDataList(string type)
    {
      if (type=="")
        {
            if (rb1.Checked == true)
                type = "Business";
            else if (rb2.Checked == true)
                type = "Address";
            else if (rb3.Checked == true)
                type = "Contact";
        }
        string Type = type;
        string name = "";
        string company = "";

        string conStr = ConfigurationManager.ConnectionStrings["cnSting_Con"].ConnectionString;
        SqlConnection con = new SqlConnection(conStr);
        SqlCommand cmd = new SqlCommand("[spx_GetBusiness]");
        cmd.Connection = con;
        con.Open();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@Alphabet", ViewState["CurrentAlphabet"]);
        cmd.Parameters.AddWithValue("@type", type);
        cmd.Parameters.AddWithValue("@name", name);
        cmd.Parameters.AddWithValue("@company", company);
        cmd.Parameters.AddWithValue("@Utype", Session["Type"].ToString());
        cmd.Parameters.AddWithValue("@uid", Session["user_id"].ToString());
        DataTable ds = new DataTable();
        SqlDataAdapter sd = new SqlDataAdapter(cmd);
        sd.Fill(ds);
        con.Close();

        if (type == "Business")
        {
            Business.DataSource = ds;
            Business.DataBind();
          }
     protected void Page_Load(object sender, EventArgs e)
    {

                Business.Visible = false;
                Address.Visible = false;
                Contact.Visible = false;
                dl_company.Visible = false; 
                ViewState["CurrentAlphabet"] = "A";
                this.GenerateAlphabets();
     }