locked
Problems with dynamically created sqldatasource RRS feed

  • Question

  • User737727417 posted

    Hi,

    My users have "demanded" to have an export function to their gridviews, and since they're running from usercontrols there's no way to modify the response stream. My workaround is to create an aspx to run in a hidden iframe. To do that, and to make it modular, I'm trying to dynamically create everything from the querystring. This *seems* to work just fine until I bind my sqldatasource to the dummy gridview. I then get "Procedure or function 'xxx' expects parameter '@NumberResults', which was not supplied." I'm all out of good ideas, so any help would be appreciated!

    Below is my entire codebehind. The aspx file only contains a dummy gridview set to automatically create columns.

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Data.SqlClient;
    
    public partial class PulseLoggMedAgentLoggExport : System.Web.UI.Page
    {
        string dato = "";
        string usergroup = "";
        string agent = "";
        string queue = "";
        string connectionString = "";
        string selectCommand = "";
        string mode = "";
        SqlDataSource ds;
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["mode"] != null)
            {
                mode = Request.QueryString["mode"].ToString();
    
                if (Request.QueryString["connection_string"] != null)
                    connectionString = Request.QueryString["connection_string"].ToString();
                if (Request.QueryString["select_command"] != null)
                    selectCommand = Request.QueryString["select_command"].ToString();
    
                if (Request.QueryString["dato"] != null)
                    dato = Request.QueryString["dato"];
                if (Request.QueryString["usergroup"] != null)
                    usergroup = Request.QueryString["usergroup"];
                if (Request.QueryString["agent"] != null)
                    agent = Request.QueryString["agent"];
                if (Request.QueryString["queue"] != null)
                    queue = Request.QueryString["queue"];
    
                if ((connectionString != "") && (selectCommand != ""))
                {
                    ds = new SqlDataSource(connectionString, selectCommand);
                    ds.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
                    ds.Selecting += new SqlDataSourceSelectingEventHandler(SqlDataSourceMain_Selecting);
                    GridView1.DataSource = ds;
                    GridView1.DataBind();
                }
            }
        }
        protected void SqlDataSourceMain_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
    //<asp:Parameter Name="date" Type="DateTime" ConvertEmptyStringToNull="true" DefaultValue="" />
    //<asp:Parameter Name="queue" Type="String" ConvertEmptyStringToNull="true" DefaultValue="" />
    //<asp:Parameter Name="agent" Type="Int32" ConvertEmptyStringToNull="true" DefaultValue="" />
    //<asp:Parameter Name="usergroup" Type="String" ConvertEmptyStringToNull="true" DefaultValue="" />
    //<asp:Parameter Name="NumberResults" Type="Int32" ConvertEmptyStringToNull="true" Direction="Output" />
    
            ds.SelectParameters.Clear();
            
            if (dato == "")
                ds.SelectParameters.Add(new Parameter("@date", DbType.DateTime, DBNull.Value.ToString()));
            else
                ds.SelectParameters.Add(new Parameter("@date", DbType.DateTime, dato)); 
    
            if (queue == "")
                ds.SelectParameters.Add(new Parameter("@queue", DbType.String, DBNull.Value.ToString()));
            else
                ds.SelectParameters.Add(new Parameter("@queue", DbType.String, queue));
    
            if (agent == "")
                ds.SelectParameters.Add(new Parameter("@agent", DbType.Int32, DBNull.Value.ToString()));
            else
                ds.SelectParameters.Add(new Parameter("@agent", DbType.Int32, agent));
    
            if (usergroup == "")
                ds.SelectParameters.Add(new Parameter("@usergroup", DbType.String, DBNull.Value.ToString()));
            else
                ds.SelectParameters.Add(new Parameter("@usergroup", DbType.String, usergroup));
    
            ds.SelectParameters.Add(new Parameter("@NumberResults", DbType.Int32, DBNull.Value.ToString()));
        }
    
        protected void GridView1_DataBound(object sender, EventArgs e)
        {
            GridViewExportUtil.Export(GridView1);
        }
    }
    


    Thursday, January 13, 2011 6:18 AM

All replies

  • User-1590642642 posted

    What line does the error occur on?

    What is  GridViewExportUtil?    another class?  

    Tuesday, January 18, 2011 2:47 PM