Link to home
Start Free TrialLog in
Avatar of zimmer9
zimmer9Flag for United States of America

asked on

In a C# application using SQL Server 2005, how to resolve the error during an INSERT "[IndexOutOfRangeException: Index was outside the bounds of the array.]?

I am developing a C# ASP.Net application and once my program executes, it stops
executing at:

command.Parameters.Add("@office", SqlDbType.VarChar).Value = rowtoappend[1];
The error message states:

[IndexOutOfRangeException: Index was outside the bounds of the array.]

How would you resolve this error?

The value of rowtoappend[1] is "" 

 public void AppendManualWSRows(string[] rowtoappend)
        {
            using (SqlConnection conn = new SqlConnection(connString))
            {
                SqlCommand command = new SqlCommand("proc_SMR_XLS_Manual_Insert", conn);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add("@bank", SqlDbType.VarChar).Value = rowtoappend[0];
                command.Parameters.Add("@office", SqlDbType.VarChar).Value = rowtoappend[1];
                command.Parameters.Add("@checknum", SqlDbType.VarChar).Value = rowtoappend[2];
                conn.Open();
                command.ExecuteNonQuery();
                conn.Close();
            }

        }I am developing a C# ASP.Net application and once my program executes, it stops
executing at:

command.Parameters.Add("@office", SqlDbType.VarChar).Value = rowtoappend[1];


[IndexOutOfRangeException: Index was outside the bounds of the array.]

How would you resolve this error?

The value of rowtoappend[1] is "" 

 public void AppendManualWSRows(string[] rowtoappend)
        {
            using (SqlConnection conn = new SqlConnection(connString))
            {
                SqlCommand command = new SqlCommand("proc_SMR_XLS_Manual_Insert", conn);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add("@bank", SqlDbType.VarChar).Value = rowtoappend[0];
                command.Parameters.Add("@office", SqlDbType.VarChar).Value = rowtoappend[1];
                command.Parameters.Add("@checknum", SqlDbType.VarChar).Value = rowtoappend[2];
                conn.Open();
                command.ExecuteNonQuery();
                conn.Close();
            }

        }
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can you expand on what the ultimate resolution was? While I appreciative of the award, I'm not sure if my comment would technically be an answer. I was anticipating a response from your to which I had intended on following up with more information.