DataGrid and SQL Server view

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt

    #1

    DataGrid and SQL Server view

    Hi,

    I'm trying to fill an ASP.NET DataGrid from a SQL-Server View. Note
    that this is a View and not a Stored Procedure.

    If i write the SQL instructions directly in the code, or if i use a
    stored procedure, it works great. But if the same SQL instructions are
    in a view, it won't work. Here it goes :


    public IDataReader SomeFunction()
    {
    SqlCommand ObjCmd = new SqlCommand();

    ObjCmd.Connecti on = m_ObjCon;
    ObjCmd.CommandT ext = "[Sales by Category]";
    ObjCmd.CommandT ype = CommandType.Sto redProcedure;

    return ObjCmd.ExecuteR eader();
    }


    It gives me an error, "The request for procedure 'Sales by Category'
    failed because 'Sales by Category' is a view object."

    My question is, is it possible to use a view instead of a stored
    procedure in this context? I'm a little confused about the difference
    between both. Thanks for help!

    Matt
  • news.microsoft.com

    #2
    Re: DataGrid and SQL Server view

    Hi Matt,

    From the perspective of ADO.Net code running in your C# program, a "View" in
    SQL Server 2000 is the equivalent of a table. You'll need to write a T-SQL
    query in your C# code, or call a stored proc that utilizes the view.

    Example: "SELECT * FROM [MyView] a WHERE a.ThisColumn = 'That';"

    - Andrew

    "Matt" <metal@rocks.co m> wrote in message
    news:dsr1hv0lfq 9e13cuj4gvfunt6 7287j32sl@4ax.c om...[color=blue]
    > Hi,
    >
    > I'm trying to fill an ASP.NET DataGrid from a SQL-Server View. Note
    > that this is a View and not a Stored Procedure.
    >
    > If i write the SQL instructions directly in the code, or if i use a
    > stored procedure, it works great. But if the same SQL instructions are
    > in a view, it won't work. Here it goes :
    >
    >
    > public IDataReader SomeFunction()
    > {
    > SqlCommand ObjCmd = new SqlCommand();
    >
    > ObjCmd.Connecti on = m_ObjCon;
    > ObjCmd.CommandT ext = "[Sales by Category]";
    > ObjCmd.CommandT ype = CommandType.Sto redProcedure;
    >
    > return ObjCmd.ExecuteR eader();
    > }
    >
    >
    > It gives me an error, "The request for procedure 'Sales by Category'
    > failed because 'Sales by Category' is a view object."
    >
    > My question is, is it possible to use a view instead of a stored
    > procedure in this context? I'm a little confused about the difference
    > between both. Thanks for help!
    >
    > Matt[/color]


    Comment

    Working...