Stored Procedure return records

A

Alan T

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();
}
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top