Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have designing in my web page The error are occur

'dataType' argument cannot be null.
Parameter name: dataType



code

private DataTable CreateDataTable()
       {
           DataTable dt = new DataTable();
           dt.Columns.Add("Size", System.Type.GetType("System.String"));
           dt.Columns.Add("SizeID", System.Type.GetType("System.Int64"));
  (_Error) dt.Columns.Add("Lamination", System.Type.GetType("System.Strings"));
           dt.Columns.Add("Amount", System.Type.GetType("System.Int64"));
           dt.Columns.Add("Noofcopies", System.Type.GetType("System.Int64"));
           dt.Columns.Add("Total", System.Type.GetType("System.Int64"));
           return dt;
       }
Posted

From the first glance: there is not such type System.Strings.

Problem solved.

But now, let's see how did you create this problem and how to avoid it. This is extremely bad coding: System.Type.GetType("System.String"), because you're using immediate string constants for argument. What happens if you mistype anything? Compiler won't help you to detect a bug. Why doing it when a decent method exist? Instead, use:

C#
//for example:
System.Type myType = typeof(System.String);


Problem prevented.
Don't get in trouble!

Good luck,
—SA
 
Share this answer
 
Comments
RakeshMeena 9-Jun-11 5:15am    
I've seen a lot many developers doing this. My 5 for pointing it out.
Sergey Alexandrovich Kryukov 9-Jun-11 5:16am    
Thank you, Rakesh. Tell those developers they are creating troubles for no reason.
--SA
DaveAuld 9-Jun-11 5:16am    
Ok, so you get my 5, for being too damn smart! :) It's people like you that help the likes of me learn, so i can't complain :)
Sergey Alexandrovich Kryukov 9-Jun-11 5:17am    
Thank you very much for your good words, Dave.
--SA
Your mistake: System.Type.GetType("System.Strings")

Use System.Type.GetType("System.String")
 
Share this answer
 
Comments
Manfred Rudolf Bihy 9-Jun-11 5:07am    
Correct! 5+
Sergey Alexandrovich Kryukov 9-Jun-11 5:11am    
I voted 4 this time. You found a bug but what's a fix? Fixing a typo? Wrong!
Please see my solution.
--SA
Look at the type specified on the error line, you have Strings instead of String (i.e. extra s)
 
Share this answer
 
Comments
Manfred Rudolf Bihy 9-Jun-11 5:07am    
Well, spotted! 5+
Sergey Alexandrovich Kryukov 9-Jun-11 5:12am    
Yes, but that's not all.
Please see my solution -- important difference.
--SA
Sergey Alexandrovich Kryukov 9-Jun-11 5:11am    
I voted 4 this time. You found a bug but what's a fix? Fixing a typo? Wrong!
Please see my solution.
--SA
System.Strings should be System.String. If System.Type.GetType can't resolve the type because it's unknown it will return null thus causing your error.

C#
private DataTable CreateDataTable()
{
    DataTable dt = new DataTable();
    dt.Columns.Add("Size", System.Type.GetType("System.String"));
    dt.Columns.Add("SizeID", System.Type.GetType("System.Int64"));
    dt.Columns.Add("Lamination", System.Type.GetType("System.String")); // Corrected to read System.String
    dt.Columns.Add("Amount", System.Type.GetType("System.Int64"));
    dt.Columns.Add("Noofcopies", System.Type.GetType("System.Int64"));
    dt.Columns.Add("Total", System.Type.GetType("System.Int64"));
    return dt;
}


Cheers!

-MRB
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 9-Jun-11 5:13am    
Same thing: I voted 4 this time. Your fixed code is not better, only a type fixed.
Please see my solution.
--SA
Your mistake: System.Type.GetType("System.Strings")
Use System.Type.GetType("System.String")
 
Share this answer
 
Use System.String to clear the error in Asp.net.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 9-Jun-11 5:15am    
Ramalinga, sorry, but you did not even explain how. Why answering just for answering? I have to vote 3.
For a correct solution, please see mine.
--SA

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