Solved

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

Posted on 2015-02-11
11
427 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
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 62

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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 62

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 62

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

19 Experts available now in Live!

Get 1:1 Help Now