469,958 Members | 1,929 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,958 developers. It's quick & easy.

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
Nov 17 '05 #1
1 3476
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" <me***@rocks.com> wrote in message
news:ds********************************@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

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by vinayak | last post: by
3 posts views Thread by Jim Heavey | last post: by
3 posts views Thread by DC | last post: by
4 posts views Thread by tshad | last post: by
3 posts views Thread by Leo | last post: by
7 posts views Thread by BobAchgill | last post: by
4 posts views Thread by Jeff User | last post: by
7 posts views Thread by RolfHerbert | last post: by
reply views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.