Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
string vertex = "select vertex_path from Tbl_AllGraphInfo where Graph_Id='" + Graph_Id + "'";
            SqlCommand cmd = new SqlCommand(vertex,con11);
            con11.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                fullpath = dr.GetString(0);

            }
            dr.Close();
//            string actresult = ((string)cmd.ExecuteScalar());
            con11.Close();
            int counter = 0;
            string[] array = fullpath.Split(';');
            string[] array2 = new string[2];
            List<string> list = new List<string>();
            for (int i = 0; i < array.Length; i++)
            {
               array2= array[i].Split(',');
               list.Add(array2[1]);


            }
            counter = 0;

            string[] pattern = (string[])list.ToArray();


What I have tried:

Index was outside the bounds of the array
Posted
Updated 15-Jul-16 23:24pm
v2

1 solution

Use the debugger and step through your application: we can't do that as we don't have access to your data.
Put a breakpoint on the first line of that code, and run it in the debugger. When execution reaches the breakpoint it will stop and let you have control. Use the debugger to examine variable contents, and step through the program line by line, working out what you expect to happen before you execute each one.
Did you what expected happen? If so, continue with the next line. If not, why not? What did happen? What was in the variables that causes this to happen?

We can't do any of this for you - we don't have access to your data, and I don't think the error is in that code - it occurs on a line you haven't shown us. So give it a try, and see what you can find out!

BTW: Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
 
Share this answer
 
Comments
Member 10779576 16-Jul-16 4:46am    
there is 45 vertex path but in for loop it take 46 element it goes " " for loop is not brake it take value that means "" vaue.. i go through barkepoint.. con i take array.lengh-1; in for loop
OriginalGriff 16-Jul-16 5:02am    
Sorry - that doesn't make any sense without seeing your screen - which I can't do.
Remember, I only get to see exactly what you type!
So try again, and explain in simple steps exactly what happens and what is in the relevant variables when it does. In particular, look at the content of array[i] before you call Split each time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900