L'index se trouve en dehors des limites du tableau
garygary54000
Messages postés2Date d'inscriptionmercredi 24 mars 2010StatutMembreDernière intervention20 mai 2010
-
20 mai 2010 à 13:24
garygary54000
Messages postés2Date d'inscriptionmercredi 24 mars 2010StatutMembreDernière intervention20 mai 2010
-
20 mai 2010 à 13:37
Salut !
Je souhaite faire une requete sql de type select , avec comme paramètre WHERE ' un tableau ' . La requete est donc inséré dans une boucle for .
Le resultat de la requete est donc aussi un tableau .
Voici le code
private void button3_Click(object sender, EventArgs e)
{
MatchCollection matches2 = Regex.Matches(fichier2, "DTSTART:([0-9]+[A-Z]+[0-9]+)");
for (int i = 0; i < matches2.Count; i++)
{
OdbcConnection connection = new System.Data.Odbc.OdbcConnection("DSN=" + UID.Text + "; UID=" + login.Text + ";PWD=" + password.Text + ";");
//string CommandText = string.Format("INSERT INTO [table] ([ressource],[DTSTART],[DTEND]) VALUES (('" + results_ressource[i] + "'),('" + tableaudtstartfinal[i] + "'),('" + tableaudtendfinal[i] + "')) ");
//OdbcCommand mycommand1 = new OdbcCommand(CommandText, connection);
connection.CreateCommand();
try
{
connection.Open();
//mycommand1.ExecuteNonQuery();
OdbcCommand DbCommand = connection.CreateCommand();
DbCommand.CommandText =(" SELECT ID from [RESSOURCE_] WHERE name=('" + results_ressource[i] + "')");
OdbcDataReader DbReader = DbCommand.ExecuteReader();
while (DbReader.Read())
{
string[] col = new string[20];
col[i] = DbReader.GetString(i);
MessageBox.Show(col[i]);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Le resultat : 1 ere message box : La valeur est bonne
Pour toute les box suivantes : L'index se trouve en dehors des limites du tableau