3
I need to get the return of one select that comes from a procedure.
I saw about using the ExecuteReader, but I’m not getting the data that’s coming in.
To procedure is fine
As the return of procedure it’s gonna be something like this and both varchar.
Item | Name Item
given a | given b
given c | given c
I thought of creating a matrix of 2 by n lines.
The problem is when it comes to ExecuteReader to get the values of the item and the item name
Here is my code
string[][] retorno = new string[2][];
string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
using(SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("Sp_SelectContratoGestores"))
{
cmd.CommandTimeout = 300;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
con.Open();
while (cmd.ExecuteReader().Read())
{
retorno[0][contador] = cmd.ExecuteReader().ToString();
contador++;
}
con.Close();
}
}
That’s right, pity that just to select one as solved, I’ll get the guy there who answered first, but thank you, really @Diegosantos
– gabrielfalieri
When I saw him I had already answered hehehe. But ta tranquil. The important thing is to kill the doubts! No competition :)
– DiegoSantos
By the way, is this way of writing the 2 by n multidimensional array correct? (2 columns n rows)
– gabrielfalieri
@gabrielfalieri, which array? The one from Reader?
– DiegoSantos
The string that takes the value of the Reader
– gabrielfalieri
But it is not multidimensional... Note that I passed the content inside a string. If I passed a number, it would be the index of the resultset.
– DiegoSantos
I already know what I will do, I will take this dataReader, play for a dataset, with this dataset I take his Count and with it I can create an array of lines the size of Count
– gabrielfalieri
Forget it, it’ll be all right
– gabrielfalieri
Dude, I don’t think it’s gonna work out not even kkkkkkkkkkkkkkkkkkkkkk Take each attribute the way I showed it. If not, only an ORM will help you
– DiegoSantos
Oh that’s... I have to play this returned data to become an excel later
– gabrielfalieri
Let’s go continue this discussion in chat.
– gabrielfalieri