Hello, I’ve a problem with this code: -------------------------------------------------------------------------------------------------------- public string makePath(string handle_class, string handle_index, string path) { string newpath = “”; DataTable tablePath = selectTable("SELECT source_index, source_class FROM Link_table WHERE destination_index = “+ handle_index +” AND destination_class = "+ handle_class); foreach(DataRow dr in tablePath.Rows) { newpath += dr[“source_index”]+ " "; newpath += selectItem(“SELECT DSObject_table.Object_title FROM DSObject_table INNER JOIN Link_table ON DSObject_table.handle_index = Link_table.destination_index AND DSObject_table.handle_class = Link_table.destination_class WHERE (Link_table.destination_index = “+ dr[“source_index”].ToString() +”) AND (Link_table.destination_class = 1)”,“Object_title”)+ “
”; newpath += path; if(dr[“source_index”].ToString() != “10”) { makePath(dr[“source_class”].ToString(), dr[“source_index”].ToString(),newpath); } else { break; } } return newpath; } -------------------------------------------------------------------------------------------------------- I’ve an SQL Server database where i want to get out the virtual path of files/documents. I’m looping this function until handle_index = 10 because thats the main document of the path. If handle_index = 10 the foreach method must break and the makePath function must return the newpath.(look at the code) If the newpath returns, the function makePath must stop. But thats the problem, it doesn’t. After the function returns the newpath it comes again at this place in the function: makePath(dr[“source_class”].ToString(), dr[“source_index”].ToString(),newpath); What i’m doing wrong? Regards, Hans de Graaf
Perhaps the looping “foreach(DataRow dr in tablePath.Rows)” returns more than 10 ? Maybe you should ask for: if(dr[“source_index”].ToString() = “10”) { makePath(dr[“source_class”].ToString(), dr[“source_index”].ToString(),newpath); return newpath; } Why is your function calling himself? I mean: You start with makePath(…) and inside the loop youre calling again for makePath!! ???
The functions calls itself because it must repeat till handle_index == 10. 10 is the main virtual folder in the database. Your code doesn’t work because if handle_index == 10 it must return the newpath and not calling the function. Do you have another solution?