473,385 Members | 1,470 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,385 software developers and data experts.

SQL Stored procedure into a datagrid

Amy
I'm having trouble getting some data into a datagrid. It works fine
for the results of the first SELECT in the stored procedure, but not
therafter.
Here's the error I get:
"A field or property with the name 'contactUID' was not found on the
selected datasource"
Relevant code below - any help woudl be appreciated.
I have this sql stored procedure:
CREATE PROCEDURE [dbo].[PC_Return_Project]

@pID int

AS

Select projName, pc_projects.freqID, requestedDeadline,
pc_projects.priorityID, dateProposed, pc_projects.statusID,
description, basecampURL, priority, freqtype, Status
from pc_projects
inner join pc_keyPriority kP on
pc_projects.priorityID=kP.priorityID
and pID = @pID
inner join pc_keyFrequency kF on pc_projects.freqID=kF.freqID
inner join pc_keyStatus kS on pc_projects.statusID=kS.statusID

Select contactUID
from PC_projectContact
where pID = @pid

Select analystUID
from PC_projectAnalyst
where pID = @pID

Select audID, audience
from PC_projectAudience
inner join pc_keyAudience kA on PC_projectAudience.audID=kA.audienceID
where projID = @pID
GO
And this method in C#:
public DataTable GetProjectTable (int pID)
{
SqlCommand cmdGetProject = new SqlCommand("PC_Return_Project", conn);
cmdGetProject.CommandType = CommandType.StoredProcedure;
cmdGetProject.Parameters.Add("@pID", pID);

conn.Open();
SqlDataAdapter daProject = new SqlDataAdapter(cmdGetProject);
DataTable dtProject = new DataTable();
daProject.Fill(dtProject);
conn.Close();

return dtProject;

}

I'm calling the method here:
int pID = (int) Session["pID"];

DataDealings sql = new DataDealings();

dgProject.DataSource = sql.GetProjectTable(pID);
dgProject.DataBind();
and this on the GUI:
<Columns>
<asp:BoundColumn HeaderText="Project Name" DataField="projName" />
<asp:BoundColumn HeaderText="Description" DataField="description" />
<asp:BoundColumn HeaderText="Frequency" DataField="freqType" />
<asp:BoundColumn HeaderText="Priority" DataField="priority" />
<asp:BoundColumn HeaderText="Date Proposed" DataField="dateProposed"
/>
<asp:BoundColumn HeaderText="Requested Deadline"
DataField="requestedDeadline" />
<asp:BoundColumn HeaderText="BaseCamp URL" DataField="basecampURL" />
<asp:BoundColumn HeaderText="Contact" DataField="contactUID" />
</Columns>

Nov 17 '05 #1
3 4514

Amy wrote:
I'm having trouble getting some data into a datagrid. It works fine
for the results of the first SELECT in the stored procedure, but not
therafter.
Here's the error I get:
"A field or property with the name 'contactUID' was not found on the
selected datasource"
Relevant code below - any help woudl be appreciated.
I have this sql stored procedure:
CREATE PROCEDURE [dbo].[PC_Return_Project]

@pID int

AS

Select projName, pc_projects.freqID, requestedDeadline,
pc_projects.priorityID, dateProposed, pc_projects.statusID,
description, basecampURL, priority, freqtype, Status
from pc_projects
inner join pc_keyPriority kP on
pc_projects.priorityID=kP.priorityID
and pID = @pID
inner join pc_keyFrequency kF on pc_projects.freqID=kF.freqID
inner join pc_keyStatus kS on pc_projects.statusID=kS.statusID

Select contactUID
from PC_projectContact
where pID = @pid

Select analystUID
from PC_projectAnalyst
where pID = @pID

Select audID, audience
from PC_projectAudience
inner join pc_keyAudience kA on PC_projectAudience.audID=kA.audienceID
where projID = @pID
GO
This stored procedure will return *multiple* resultsets. Since a
DataTable can only hold one resultset, only the first resultset will be
in your dtProject.

[snip] and this on the GUI:
<Columns>
<asp:BoundColumn HeaderText="Project Name" DataField="projName" />
<asp:BoundColumn HeaderText="Description" DataField="description" />
<asp:BoundColumn HeaderText="Frequency" DataField="freqType" />
<asp:BoundColumn HeaderText="Priority" DataField="priority" />
<asp:BoundColumn HeaderText="Date Proposed" DataField="dateProposed"
/>
<asp:BoundColumn HeaderText="Requested Deadline"
DataField="requestedDeadline" />
<asp:BoundColumn HeaderText="BaseCamp URL" DataField="basecampURL" />
<asp:BoundColumn HeaderText="Contact" DataField="contactUID" />
</Columns>


This GUI attempts to find columns named projName, description, ...,
contactUID in the DataTable it is bound to. However, there is no column
contactUID in the first resultset from your SP, so there is no such
column in the DataTable these columns are binding to, hence the error.

To fix: I can't be sure, but it looks from your SP as though the first
SELECT returns multiple rows? And you want to display them with the
contactUID (which will be the same for all the rows?) in the last
column. In which case you could just add a subquery:

, (Select contactUID from PC_projectContact where pID = @pid)

to the SELECT list of the first query in the SP and that will do the
trick.
Just to reiterate, if you want to get at the later resultsets of the
SP, you will need to change something, as at the moment GetProjectTable
returns a DataTable, which can only hold one resultset.

--
Larry Lard
Replies to group please

Nov 17 '05 #2
Amy
Thanks, that helps.

Unfortunately, it still doesn't solve the problem - the first SELECT
only returns one result, but the ContactUID returns multiple
(that is, 1 Project to several ContactUIDs).

I added the subquery, and was chided for this ("Subquery returned more
than 1 value. This is not permitted when the subquery follows =, !=,
<, <= , >, >= or when the subquery is used as an expression.")

Is there a way around this?

Thanks,

--Amy
On 19 Oct 2005 08:52:25 -0700, "Larry Lard" <la*******@hotmail.com>
wrote:

Amy wrote:
I'm having trouble getting some data into a datagrid. It works fine
for the results of the first SELECT in the stored procedure, but not
therafter.
Here's the error I get:
"A field or property with the name 'contactUID' was not found on the
selected datasource"
Relevant code below - any help woudl be appreciated.
I have this sql stored procedure:
CREATE PROCEDURE [dbo].[PC_Return_Project]

@pID int

AS

Select projName, pc_projects.freqID, requestedDeadline,
pc_projects.priorityID, dateProposed, pc_projects.statusID,
description, basecampURL, priority, freqtype, Status
from pc_projects
inner join pc_keyPriority kP on
pc_projects.priorityID=kP.priorityID
and pID = @pID
inner join pc_keyFrequency kF on pc_projects.freqID=kF.freqID
inner join pc_keyStatus kS on pc_projects.statusID=kS.statusID

Select contactUID
from PC_projectContact
where pID = @pid

Select analystUID
from PC_projectAnalyst
where pID = @pID

Select audID, audience
from PC_projectAudience
inner join pc_keyAudience kA on PC_projectAudience.audID=kA.audienceID
where projID = @pID
GO
This stored procedure will return *multiple* resultsets. Since a
DataTable can only hold one resultset, only the first resultset will be
in your dtProject.

To fix: I can't be sure, but it looks from your SP as though the first
SELECT returns multiple rows? And you want to display them with the
contactUID (which will be the same for all the rows?) in the last
column. In which case you could just add a subquery:

, (Select contactUID from PC_projectContact where pID = @pid)

to the SELECT list of the first query in the SP and that will do the
trick.
Just to reiterate, if you want to get at the later resultsets of the
SP, you will need to change something, as at the moment GetProjectTable
returns a DataTable, which can only hold one resultset.

Nov 17 '05 #3

Well, this is where my lack of knowledge about the database shows :)
What you need to do is modify the SP appropriately (using SQL Query
Analyzer or whatever) until it returns the results you want: that is,
it returns what you want to bind into the displayed table as the
*first* resultset. Then your databinding code will 'just work'.
Amy wrote:
Thanks, that helps.

Unfortunately, it still doesn't solve the problem - the first SELECT
only returns one result, but the ContactUID returns multiple
(that is, 1 Project to several ContactUIDs).

I added the subquery, and was chided for this ("Subquery returned more
than 1 value. This is not permitted when the subquery follows =, !=,
<, <= , >, >= or when the subquery is used as an expression.")

Is there a way around this?

Thanks,

--Amy
On 19 Oct 2005 08:52:25 -0700, "Larry Lard" <la*******@hotmail.com>
wrote:

Amy wrote:
I'm having trouble getting some data into a datagrid. It works fine
for the results of the first SELECT in the stored procedure, but not
therafter.
Here's the error I get:
"A field or property with the name 'contactUID' was not found on the
selected datasource"
Relevant code below - any help woudl be appreciated.
I have this sql stored procedure:
CREATE PROCEDURE [dbo].[PC_Return_Project]

@pID int

AS

Select projName, pc_projects.freqID, requestedDeadline,
pc_projects.priorityID, dateProposed, pc_projects.statusID,
description, basecampURL, priority, freqtype, Status
from pc_projects
inner join pc_keyPriority kP on
pc_projects.priorityID=kP.priorityID
and pID = @pID
inner join pc_keyFrequency kF on pc_projects.freqID=kF.freqID
inner join pc_keyStatus kS on pc_projects.statusID=kS.statusID

Select contactUID
from PC_projectContact
where pID = @pid

Select analystUID
from PC_projectAnalyst
where pID = @pID

Select audID, audience
from PC_projectAudience
inner join pc_keyAudience kA on PC_projectAudience.audID=kA.audienceID
where projID = @pID
GO


This stored procedure will return *multiple* resultsets. Since a
DataTable can only hold one resultset, only the first resultset will be
in your dtProject.

To fix: I can't be sure, but it looks from your SP as though the first
SELECT returns multiple rows? And you want to display them with the
contactUID (which will be the same for all the rows?) in the last
column. In which case you could just add a subquery:

, (Select contactUID from PC_projectContact where pID = @pid)

to the SELECT list of the first query in the SP and that will do the
trick.
Just to reiterate, if you want to get at the later resultsets of the
SP, you will need to change something, as at the moment GetProjectTable
returns a DataTable, which can only hold one resultset.


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how...
2
by: Max | last post by:
Is it possible or more effecient to use a stored procedure to populate a datagrid when using datagrid or custom paging? Is it (ADO.NET?) pulling the entire table into the dataset or is it just...
5
by: microsoft.private.windows.netserver.setup | last post by:
I have a very strange thing occurring in the program. I have a dataset retrieved from a stored procedure that just select * from a table. I then try to use the SQlCommandBuilder on the dataset,...
1
by: .Net Sports | last post by:
i have an aliased column in an sql statement that works fine when displaying its output in a datagrid, but when I transfer the sql statement into a stored procedure , the datagrid can't see it. I...
6
by: Jim | last post by:
Can someone, please, show me how to display the results of a stored procedure in a VB.NET datagrid on a winform? I'm a newbie. Here's my SQL 2000 stored precedure that returns the status of...
4
by: jaYPee | last post by:
I have downloaded some source code but I want this to convert the results into datagrid. dr = cmd.ExecuteReader() '**************************************** ' SHOW THE RESULTS...
10
by: Rich | last post by:
I have a stored procedure on Sql Server2k. I can fill a data table which I can append to a dataset using an ADODB recordset object which gets populated from a command object that runs the sp. I...
3
by: Assimalyst | last post by:
Hi, I have two methods. In one i would like to create a string from a stored procedure to pass to the second which populates a datagrid. private void method() { string sqlString =...
3
by: FrustratedNoob | last post by:
I've got a database that I've been working on for over a year and a half but I've just recently finished the back end to the point of feeling comfortable with starting on a front end. So while...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.