Solved

asp.net c# System.ArgumentException: Column requires a valid DataType. Passing string "E"

Posted on 2015-02-11
11
510 Views
Last Modified: 2015-02-11
Hello,
I'm creating a datatable, in a class.
It requires a string to determine which table to create.
When done it passes the table back.  
When the class is called with a "C" or "S" it works.  When the class is called with a "E" it fails.
If the "E" group is removed it works great.  Tried replacing the "E" with "X" still same problem.

Here's the .aspx.cs  page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Xml;
using System.Data.SqlClient;
using System.IO;

using CreateCustomTable;
public partial class DataIn : System.Web.UI.Page
{
    public const string path = @"C:\inetpub\wwwroot\XXX\Files\App\";
    public DataTable dtCustom, dtCustomEdit, dtSI;
    public DataRow rowC, rowCE, rowSIU;

    protected void Page_Load(object sender, EventArgs e)
    {
            
        string CustomEditFileName = "V_CUSTOM_EDITS.xml";
        string CustomEditFilePath = path + CustomEditFileName;
        dtCustomEdit = CreateCustomTable2.CustomTable("E");       <-------  This is where it fails
        XmlDataSource CustomEditXML = new XmlDataSource();
        CustomEditXML.DataFile = CustomEditFilePath;

        string CustomFileName = "V_CUSTOM.xml";
        string CustomFilePath = path + CustomFileName;
        dtCustom = CreateCustomTable2.CustomTable("C");
        XmlDataSource CustomXML = new XmlDataSource();
        CustomXML.DataFile = CustomFilePath;
                
        string SIFileName = "V_UNIV_SICM.xml";
        string SIFilePath = path + SIFileName;
        dtSI = CreateCustomTable2.CustomTable("S");
        XmlDataSource SIXML = new XmlDataSource();
        SIXML.DataFile = SIFilePath;

Open in new window


Here's the class code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace CreateCustomTable
{
public class CreateCustomTable2
{
public static DataTable CustomTable(string thisTable)
{
    //Custom_Edits Table
    DataTable dt = new DataTable();
    DataColumn dc = default(DataColumn);

    if (thisTable == "E")    //Custom Edits Table
    {
	dc = new DataColumn();
	dc.DataType = Type.GetType("System.String");
	dc.ColumnName = "I_CUST_CSTM_FLD";
	dt.Columns.Add(dc);

	dc = new DataColumn();
	dc.DataType = Type.GetType("System.String");
	dc.ColumnName = "C_EDIT_TYP";
	dt.Columns.Add(dc);

	dc = new DataColumn();
	dc.DataType = Type.GetType("System.Integer");
	dc.ColumnName = "N_FLD_EDIT_SEQ_NO";
	dt.Columns.Add(dc);
    }

    if (thisTable == "C")    //Custom Table
    {
	dc = new DataColumn();
	dc.DataType = Type.GetType("System.String");
	dc.ColumnName = "N_FLD_DT_ENTY_LEN";
	dt.Columns.Add(dc);

	dc = new DataColumn();
	dc.DataType = Type.GetType("System.String");
	dc.ColumnName = "M_CD_COLM";
	dt.Columns.Add(dc);

	dc = new DataColumn();
	dc.DataType = Type.GetType("System.String");
	dc.ColumnName = "T_FLD_LBL";
	dt.Columns.Add(dc);

	dc = new DataColumn();
	dc.DataType = Type.GetType("System.String");
	dc.ColumnName = "T_XML_OUTPT_LBL";
	dt.Columns.Add(dc);
    }

    if (thisTable == "S")    //SICM Table
    {
	dc = new DataColumn();
	dc.DataType = Type.GetType("System.String");
	dc.ColumnName = "I_CUST";
	dt.Columns.Add(dc);

	dc = new DataColumn();
	dc.DataType = Type.GetType("System.String");
	dc.ColumnName = "M_CD_COLM";
	dt.Columns.Add(dc);

	dc = new DataColumn();
	dc.DataType = Type.GetType("System.String");
	dc.ColumnName = "T_XML_OUTPT_LBL";
	dt.Columns.Add(dc);
    }
    return (dt);
}
}
}

Open in new window


Any ideas?
JS
0
Comment
Question by:jshesek
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 40603963
dc = new DataColumn();
      dc.DataType = Type.GetType("System.Integer");
      dc.ColumnName = "N_FLD_EDIT_SEQ_NO";

That is the only column with a system.integer.  I guess that is the problem - try changing to other types such as long
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40603979
Try changing this line of code,

dc.DataType = Type.GetType("System.Integer");

To this

dc.DataType = Type.GetType("System.Int32");
0
 
LVL 1

Author Comment

by:jshesek
ID: 40603989
Changed it but no luck.  Here's the web page error msg:
Server Error in '/AppCodesList' Application.

Column requires a valid DataType.
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

 Exception Details: System.ArgumentException: Column requires a valid DataType.

Source Error:

Line 26:         string CustomEditFileName = "V_CUSTOM_EDITS.xml";
Line 27:         string CustomEditFilePath = path + CustomEditFileName;
Line 28:         dtCustomEdit = CreateCustomTable2.CustomTable("E");
Line 29:         XmlDataSource CustomEditXML = new XmlDataSource();
Line 30:         CustomEditXML.DataFile = CustomEditFilePath;

Source File:  c:\inetpub\wwwroot\AppCodesList\DataIn.aspx.cs    Line:  28

Stack Trace:

[ArgumentException: Column requires a valid DataType.]
   System.Data.DataColumn.set_DataType(Type value) +2137645
   CreateCustomTable.CreateCustomTable2.CustomTable(String thisTable) +269
   DataIn.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\AppCodesList\DataIn.aspx.cs:28
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +92
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34212
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:jshesek
ID: 40604003
Thank you Fernando - It worked!

I've been working in VB and now starting C#.  So could you do me a favor?  Why didn't System.Integer work but System.Int32 did?

JS
0
 
LVL 1

Author Closing Comment

by:jshesek
ID: 40604008
Changing the data type was correct.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40604026
Why didn't System.Integer work but System.Int32 did?
Because the Integer type does not exist in C#... only Int32 does. In VB.NET, Integer is just an alias for Int32. It is there to ease the transition of VB6 developers into .NET. If you "F12" (i.e. Go To Definition) while your cursor is on the Integer keyword, you will see the Object Browser show up, and you will note that the OB navigates to System.Int32. You have to be careful when you translate VB to C# for reasons such as this.

You'll notice the same behavior in C# if you ever use the int keyword. It is also an alias for Int32, but it only exists in C#. If you were to translate c# to VB, you'd encounter a similar issue if you encounter any ints.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40604034
In C# there is no data type called Integer or integer it is int, int16, int32 and int64 which are aliases for the CLR Data types Int16, Int32 and Int64. So in this case you needed to use System.Int32.
0
 
LVL 1

Author Comment

by:jshesek
ID: 40604274
Thanks Again.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40604323
Not a problem jshesek, glad I was able to help.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 40605014
I'm rather surprised you got this error message about the column requiring a valid data type and not another message about it not recognising what System.Integer was.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question