Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello people,

I have a database with table called "contacts". I have written a stored procedure to count the number of rows some thing like this :
SQL
ALTER PROCEDURE countentries
	/*
	(
	@parameter1 int = 5,
	@parameter2 datatype OUTPUT
	)
	*/
AS
select Name ,Count(*) As Count from contacts
group by Name 
	/* SET NOCOUNT ON */
	RETURN

Now I assign this to the SqlDataSource:
none
SelectCommandType="StoredProcedure" SelectCommand="countentries"

The page gives me an error saying :
A field or property with the name 'Contact' was not found on the selected data source.

Thanks
Posted
Updated 25-Aug-13 6:47am
v3
Comments
Mahesh Bailwal 25-Aug-13 12:19pm    
can you share code which is calling this SP.
Rahul VB 25-Aug-13 12:33pm    
Hello Sir,

I tried it for Details view like this :

<asp:DetailsView id="dv" DataSourceID="sql" AllowPaging="true" AutoGenerateEditButton="true" AutoGenerateDeleteButton="true" AutoGenerateInsertButton="true" AutoGenerateRows="false" CssClass="detailsview" PagerSettings-Mode="NumericFirstLast" runat="server"><fields><asp:BoundField DataField="Name" ReadOnly="true" HeaderText="Person Name" InsertVisible="true" /><asp:BoundField DataField="Count" HeaderText="Count" ReadOnly="false" InsertVisible="true" />

It failed but works for grid view.

Thanks,
Rahul

1 solution

Check your bindings: it's possible you are linking to "Contact" instead of "Contacts" - the name in the error message is singular, the name in the stored procedure is plural.
 
Share this answer
 
Comments
Rahul VB 25-Aug-13 12:27pm    
Thanks sir, i am the same idisposable one whom you gave a homework :) :) :) thanks for solution because i did check the Contact field which led me to the right solution. hehe thanks again.

Rahul
OriginalGriff 25-Aug-13 12:30pm    
You're welcome!
(We won't Dispose of you yet, we haven't finished *using* you! :laugh: )
Rahul VB 25-Aug-13 12:32pm    
Sir, my code was :


Repected People,

I wrote a stored procedure which was to display the number of times a name was repeated.

So i wrote the procedure as above stated , let me reformulate :

STORED PROCEDURE:

ALTER PROCEDURE countentries
/*
(
@parameter1 int = 5,
@parameter2 datatype OUTPUT
)
*/
AS
select Name ,Count(*) As Count from contacts
group by Name
/* SET NOCOUNT ON */
RETURN

Now in the SQLDataSource i did something like this :

<pre lang="xml"><asp:SqlDataSource ID="sql" runat="server" ConnectionString="<%$ ConnectionStrings:contacts %>" SelectCommandType="StoredProcedure" SelectCommand="countentries" /></pre>

I wanted to display the count of "Name" column, i finally used a grid view to show the result.
The grid view extracted the result out of my select statement.

But my experiment was to try it out on a Details View, but it failed let me show you the code:

<pre lang="xml"><asp:DetailsView id="dv" DataSourceID="sql" AllowPaging="true" AutoGenerateEditButton="true" AutoGenerateDeleteButton="true" AutoGenerateInsertButton="true" AutoGenerateRows="false" CssClass="detailsview" PagerSettings-Mode="NumericFirstLast" runat="server"><Fields><asp:BoundField DataField="Name" ReadOnly="true" HeaderText="Person Name" InsertVisible="true" /><asp:BoundField DataField="Count" HeaderText="Count" ReadOnly="false" InsertVisible="true" /> </Fields></asp:DetailsView></pre>


Thanks
OriginalGriff 26-Aug-13 6:23am    
When you say "it failed", that's not actually very helpful!
Unfortunately, there are a lot more ways that something can fail, than there are that it can succeed! :laugh:
So perhaps a little more detail as to what happened, particularly what it did that you didn't want it to, and what it didn't do that you did. Any error messages would help as well...
CPallini 25-Aug-13 12:47pm    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900