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
Solved

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

Posted on 2015-02-11
11
458 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 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

840 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