I am trying to figure out a way to execute the following stored procedure using C#.
ALTER PROCEDURE spLoadClients
@NetworkingChannel nvarchar(50)
AS
SELECT
Client_Groups
FROM
ClientTable
WHERE
Networking_Channel = (@NetworkingChannel)
RETURN
The stored procedure is correct. I just need to find the proper method to execute it using C#.
Here is what I tried:
SqlDataReader reader;
string UpdateCommand = "spLoadClients";
using (SqlConnection sqlConnectionCmdString = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Shawn\Documents\Visual Studio 2010\Projects\Server\database\ClientRegit.mdf;Integrated Security=True;User Instance=True"))
using (SqlCommand sqlCommand = new SqlCommand(UpdateCommand, sqlConnectionCmdString))
{
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.Parameters.Add("@NetworkingChannel", SqlDbType.NVarChar).Value = IntializedNetworks[i];
sqlConnectionCmdString.Open();
reader = sqlCommand.ExecuteReader();
// Data is accessible through the DataReader object here.
IntializedPostNet[i] = reader[i].ToString(); //trying to add data from reader into an array errors here
sqlConnectionCmdString.Close();
}
I keep getting an error that says
Invalid attempt to read when no data is present.
What am I doing wrong?