473,386 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 3691
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
3
by: vinayak | last post by:
Hi I am displaying data in Datagrid in ASP.NET with Edit/Update functionality for each row. On the same page I have 2 Button controls which submits the request to server. These button controls...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
3
by: DC | last post by:
Dear ASP.Net Experts, In ASP, I can write something like this: <table> <tr> <th align=left>ID</th> <th align=left>Product Name</th> <th align=left>Price</th> </tr> <%
4
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a...
3
by: Leo | last post by:
I have a datagrid with the first column as a Edit,Update,Cancel button column. The other 5 columns are template columns. When I click the Edit button in IE6 the row correctly displays the...
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
7
by: BobAchgill | last post by:
I am trying to decide which of these controls to use to implement letting my user select a full row from MyList. The MyList has several columns which would be nice to sort by at run time. The...
4
by: Jeff User | last post by:
Hi I tryed to solve this problem over in the framework.asp group, but still am having trouble. Hope someone here can help. using .net 1.1, VS 2003 and C# I have an asp.DataGrid control with a...
7
by: RolfHerbert | last post by:
Hi all, Source code below. I am using an sqldatasorce to populate a datagrid. I am using datakeyIds. I am interested in two keys which I have added to the datakeyids, however if either of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.