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

Stored Procedure return records

I have a SP:

CREATE PROCEDURE dbo.users_name
as
select name
from users
order by name

Here's my C# code:
public string[] GetUserNames()
{
SqlCommand objCommand = new SqlCommand("users_name", _Conn);
objCommand.CommandType = CommandType.StoredProcedure;
_Conn.Open();
objCommand.Connection.Close();
objCommand.Connection.Open();
objCommand.ExecuteNonQuery();

// how so I assign the names from the stored procedure to the return array
of string?

_Conn.Close();
}
Jun 30 '06 #1
2 4700
Either use a DataAdapter with a dataset, or use a DataReader.

See here for an example:
http://msdn2.microsoft.com/en-us/library/haa3afyz.aspx

"Alan T" <al*************@yahoo.com.au> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
I have a SP:

CREATE PROCEDURE dbo.users_name
as
select name
from users
order by name

Here's my C# code:
public string[] GetUserNames()
{
SqlCommand objCommand = new SqlCommand("users_name", _Conn);
objCommand.CommandType = CommandType.StoredProcedure;
_Conn.Open();
objCommand.Connection.Close();
objCommand.Connection.Open();
objCommand.ExecuteNonQuery();

// how so I assign the names from the stored procedure to the return array
of string?

_Conn.Close();
}

Jun 30 '06 #2
You don't want to use ExecuteNonQuery as that returns no resultset. Use
ExecuteReader or DataAdapter.Fill to fill a DataSet. Then just iterate over
the rows, assigning the correct column value to your array.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Alan T" wrote:
I have a SP:

CREATE PROCEDURE dbo.users_name
as
select name
from users
order by name

Here's my C# code:
public string[] GetUserNames()
{
SqlCommand objCommand = new SqlCommand("users_name", _Conn);
objCommand.CommandType = CommandType.StoredProcedure;
_Conn.Open();
objCommand.Connection.Close();
objCommand.Connection.Open();
objCommand.ExecuteNonQuery();

// how so I assign the names from the stored procedure to the return array
of string?

_Conn.Close();
}

Jun 30 '06 #3

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

Similar topics

8
by: C Kirby | last post by:
In SQL Server 2000, I've got a rather lengthy stored procedure, which creates a lot of temporary tables as it processes down through a few sets of data. When testing it through Query Analyzer, it...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
5
by: Timppa | last post by:
Hi, Could anyone help me with my problem ? Environment: Access 2000 and Sql Server 2000. I have a stored procedure as follows: DROP table1 SELECT alias1.field1,alias2.field2,table2.field6...
6
by: Wojciech Wendrychowicz | last post by:
Hello to All, I'm trying to retrieve records from AS/400 in an VBA application. So, I've made an RPG program, then a stored procedure wchich calls that RPG program, and finally some VBA code to...
1
by: Sreeneet | last post by:
Hi all, I want to call a stored procedure which is written in SQL Server from an ms-access query. It is having some parameters also and the stored procedure will return some records. Is there...
7
by: Siv | last post by:
Hi, I have a stored procedure that I want to execute and then wait in a loop showing a timer whilst it completes and then carry on once I get notification that it has completed. The main reason...
7
by: ashtek | last post by:
Hi, I have a generic function that executes a stored procedure & returns a data table. Code: === public static DataTable ExecuteStoredProcedure(string strProc,SqlParameter paramArray) {...
9
by: fniles | last post by:
I am using VB.NET 2003 and SQL2000 database. I have a stored procedure called "INSERT_INTO_MYTABLE" that accepts 1 parameter (varchar(10)) and returns the identity column value from that table....
1
by: Lin100 | last post by:
Access ADP and Stored Procedure Did not Return Any Records Access 2002 and SQL 2000 Server I have a form named "Selector", and it have four combo boxes and a subform named...
3
by: stockton | last post by:
I have written the following Stored Procedure in an attempt to update two tables in the same database reliably but unfortunately it is not too successful. I ocassionaly end up with only the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.