DataGrid and SQL Server view

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default 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.Connection = m_ObjCon;
    ObjCmd.CommandText = "[Sales by Category]";
    ObjCmd.CommandType = CommandType.StoredProcedure;

    return ObjCmd.ExecuteReader();
    }


    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
    Matt Guest

  2. Similar Questions and Discussions

    1. Problem keeping the datagrid view intact after updating
      >NET 2003, vb code behind. I am having a problem with the look of a page with a datagrid. I have the grid populated, and it can be a couple of...
    2. Maintaining view state in datagrid
      hi all, I have a datagrid in my asp.net page. In that datagrid, i have paging enabled. And one template column having checkbox control in...
    3. Can't view datagrid html source in IE
      I have a weird problem. I have a webpage that displays a datagrid with data but when I use IE to view the html representation, the source has no...
    4. datagrid generated with rows from a view and its dillema
      Hello, I have a datagrid populated with rows from a view. Because they are from a view, the rows are not actual database records, and therefore...
    5. datagrid created from a view
      Hello, I have a datagrid populated with rows from a view. Because they are from a view, the rows are not actual database records, and therefore...
  3. #2

    Default 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.com> wrote in message
    news:dsr1hv0lfq9e13cuj4gvfunt67287j32sl@4ax.com...
    > 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.Connection = m_ObjCon;
    > ObjCmd.CommandText = "[Sales by Category]";
    > ObjCmd.CommandType = CommandType.StoredProcedure;
    >
    > return ObjCmd.ExecuteReader();
    > }
    >
    >
    > 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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139