Data type conversions problem
-
I have an C# ASP.NET web page. I have this conversion problem with my string array to my session variable. string[] stModArray = (string[])Session["modArray"]; Any suggestions...... Thanks in advance!! Michael
-
I have an C# ASP.NET web page. I have this conversion problem with my string array to my session variable. string[] stModArray = (string[])Session["modArray"]; Any suggestions...... Thanks in advance!! Michael
Hello, As the Session["modArray"] is only returning a string or null you can not cast it directly to string[]. You would have to create an string[] instance and add the result string to the array (at the index you would like it to be). To make it dynamic, you caould use a System.Collections.Specialized.StringCollection (with the "add" method) instead of string[]. P.S.: allways make a !=null check. Hope it helps! All the best, Martin
-
I have an C# ASP.NET web page. I have this conversion problem with my string array to my session variable. string[] stModArray = (string[])Session["modArray"]; Any suggestions...... Thanks in advance!! Michael
Do this: object o = Session["modArray"]; and check in the debugger to see what's actually stored there. If it's not a string[], you can't turn it into one, at least not like this.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Do this: object o = Session["modArray"]; and check in the debugger to see what's actually stored there. If it's not a string[], you can't turn it into one, at least not like this.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
Ok, what I have in this variable are three primary key numbers, so what's getting stored is an int. But the reason why I'm using a string is because I need to return the length for my for loop so the user can cycle backwards and forward viewing each record. -> There are no nulls getting passed in, what's getting passed in is correct. This is the snippart of the code that I'm using to try and do what I've just explaned. Once again since I'm I using a loop, objects and such don't have the length function :'( private void nextMod() { string[] stModArray = (string[])Session["modArray"]; for (int i=0; i