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();
            }

        }
zimmer9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Try putting this code into your function (somewhere before the offending line!):

if (rowtoappend.Length > 1) System.Diagnostics.Debugger.Break();

Open in new window


Does the application break (as in breakpoint) at that line once you run the application?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
käµfm³d 👽Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.