Member 11143969 Ответов: 1

Как решить пространство имен методов


bool SQLExecuteBatch(string[] strQueryText)
{
    bool Success = false;
   
    using (SqlConnection cnSQL = new SqlConnection(conStr))
    {
        cnSQL.Open();
        SqlCommand cmd = cnSQL.CreateCommand();
        SqlTransaction stBatch;

        stBatch = cnSQL.BeginTransaction("SampleTransaction");

        cmd.Connection = cnSQL;
        cmd.Transaction = stBatch;

        try
        {
            for (int i = 0; (i <= (strQueryText.Length - 1)); i++)
            {
                cmd.CommandText = strQueryText(i);
                cmd.ExecuteNonQuery();
            }

            
            stBatch.Commit();
            Success = true;
        }
        catch (Exception ex1)
        {
            Cursor.Current = Cursors.Default;
            MessageBox.Show(("SQLExecuteBatch request can not be performed due to the following..." + ("\r" + ("\r"
                            + (ex1.Message + ("\r" + ("\r" + "Changes were not applied to the target data.")))))), "Database Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
           
            try
            {
                stBatch.Rollback();
            }
            catch (Exception ex2)
            {
               
                Cursor.Current = Cursors.Default;
                MessageBox.Show(("SQLExecuteBatch rollback attempt failed..." + ("\r" + ("\r" + ex2.Message))), "Database Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            Success = false;
        }

    }

    return true;
}

у меня есть проблема strQueryText
for (int i = 0; (i <= (strQueryText.Length - 1)); i++)
{
    cmd.CommandText = strQueryText(i);
    cmd.ExecuteNonQuery();
}


Что я уже пробовал:

я перепробовал все, что знаю.

CPallini

В чем вопрос (или даже проблема)? Не могли бы вы дать более подробное описание?

1 Ответов

Рейтинг:
1

OriginalGriff

C#использует квадратные скобки для индексации массива, а не круглые. Попробуй:

cmd.CommandText = strQueryText[i];