Solved

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

Posted on 2015-02-11
11
396 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
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
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 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
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
Comment Utility
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
 
LVL 1

Author Comment

by:jshesek
Comment Utility
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
Comment Utility
Changing the data type was correct.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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 62

Expert Comment

by:Fernando Soto
Comment Utility
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
Comment Utility
Thanks Again.
0
 
LVL 62

Expert Comment

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

Expert Comment

by:AndyAinscow
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now