Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2015-02-11
11
Medium Priority
?
584 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 45

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 64

Accepted Solution

by:
Fernando Soto earned 2000 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 2

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 2

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 2

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 64

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 2

Author Comment

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

Expert Comment

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

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

618 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