Hi guys this is one project im working on but i found a problem when in the main, im calling the "SQL" method. Acording to my knowledge it supposed to go read al the array save the info and then pass that info to be used on "main" But when i watch the length of the array it has the exact amount(4) i ask to read(idk if im making a mistake with some code) but when it goes to the main it changes to 1
public string SQL(string strSQL, string[] Regreso)
{
string strError;
string strRegistro;
Array.Resize(ref Regreso, 1);
if (gStrCN == "")
{
return "No login";
}
SqlConnection DB = new SqlConnection();
try
{
DB.ConnectionString = gStrCN;
DB.Open();
SqlCommand cmd = new SqlCommand(strSQL, DB);
SqlDataReader REGISTRO = cmd.ExecuteReader();
while (REGISTRO.Read())
{
strRegistro = "";
for (int i = 0; i < REGISTRO.FieldCount; i++)
{
strRegistro = strRegistro + REGISTRO.GetValue(i) + "¨";
}
Regreso[Regreso.Length - 1] = strRegistro;
Array.Resize(ref Regreso, Regreso.Length + 1);
}
REGISTRO.Close();
Array.Resize(ref Regreso, Regreso.Length - 1); // here his size its 4
return "";
}
catch (Exception ex)
{
strError = ex.Message;
return strError;
}
finally
{
DB.Close();
}
}
The problem its here when i try to run the "Main" and i found that when i call the Variable "Regreso" as paramter it only came with 1 data instead of 4. The rest of the code it does exactly what i want, but i don't know why Regreso only return with 1 value
static void Main(string[] args)
{
string strError;
string strSQL;
string strLinea;
int i;
string[] Regreso = { " " };
ClsBD BD = new ClsBD();
strError = BD.Login("DESKTOP", "PRUEBAS", "ID", "PASS");
if (strError == "")
{
strSQL = "select cli_codigo,cli_descripcion,cli_rif from mae_cc_clientes WHERE CLI_CODIGO <='100'";
strError = BD.SQL(strSQL, Regreso); //<-- here is where only has 1 value
if (strError == "")
{
for (i = 0; i < Regreso.Length; i++)
{
strLinea = Regreso[i];
MessageBox.Show(strLinea, "Registro: " + i + 1, MessageBoxButtons.OK);
}
//MessageBox.Show("XXXX", "Error", MessageBoxButtons.OK);
}
else
{
MessageBox.Show("XXXX " + strError, "Error", MessageBoxButtons.OK);
}
}
else
{
MessageBox.Show("XXX error: " + strError, "titulo", MessageBoxButtons.OK);
}
}