Good morning, I would like to know how I can extract all the rows of a certain field in variables (String) using C#.
For example:
Campo = Usuario
rows of said field:
Juan
Ana
Jose
put them in variables like this:
String nombre1 --> Juan
String nombre2 --> Ana
String nombre3 --> Jose
PS: I use sqlserver
PD2: I have the following fields: Id_User
, Usuario
andPass
Attached current code:
conexion.Open();
SqlCommand cmd = conexion.CreateCommand();
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
string nombre = reader.GetString(1);
int cant = nombre.Count();
conexion.Close();
The quick answer is: at compile time you can NOT create variables with those kind of names.
What you can do is create a collection of
string
s where you can explore the names like this:Consider that doing it on a type variable
string[]
implies that you previously know (in some way) its final size. If not, consider creating oneList<string>
to which you can add n number of elements.To traverse it, a loop is enough: