2.0 : DataColumn.DataType

Discussion in 'Microsoft ADO .NET' started by John A Grandy, Feb 17, 2006.

  1. I took this code right out of the VS05 docs , placed it in a method in a
    separate class , from the page instantiate that class and call the method
    ..... error thrown:

    using System.Data;

    DataColumn dc = new DataColumn("Int32Col");

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

    Throws error:

    System.ArgumentException was unhandled by user code
    Message="Column requires a valid DataType."
    Source="System.Data"
    StackTrace:
    at System.Data.DataColumn.set_DataType(Type value)
    at TasksDataTier.ReadTasks(DataTable& dt) in
    c:\code\2.0\gui\code\App_Code\TasksDataTier.cs:line 164
    at TaskManagerWithCode.ReadTasks() in
    c:\code\2.0\gui\code\TaskManagerWithCode.aspx.cs:line 31
    at TaskManagerWithCode.Page_Load(Object sender, EventArgs e) in
    c:\code\2.0\gui\code\TaskManagerWithCode.aspx.cs:line 20
    at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,
    Object o, Object t, EventArgs e)
    at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object
    sender, EventArgs e)
    at System.Web.UI.Control.OnLoad(EventArgs e)
    at System.Web.UI.Control.LoadRecursive()
    at System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    :
     
    John A Grandy, Feb 17, 2006
    #1
    1. Advertisements

  2. Re: DataColumn.DataType

    Hi John,

    You have a trailing space after Int32.
    Anyway it is better to do it this way:
    dc.DataType = typeof(int);

    --
    Miha Markic [MVP C#]
    RightHand .NET consulting & development www.rthand.com
    Blog: http://cs.rthand.com/blogs/blog_with_righthand/

    "John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
    news:O4yqIZ$...
    >I took this code right out of the VS05 docs , placed it in a method in a
    >separate class , from the page instantiate that class and call the method
    >.... error thrown:
    >
    > using System.Data;
    >
    > DataColumn dc = new DataColumn("Int32Col");
    >
    > dc.DataType = System.Type.GetType("System.Int32 ");
    >
    > Throws error:
    >
    > System.ArgumentException was unhandled by user code
    > Message="Column requires a valid DataType."
    > Source="System.Data"
    > StackTrace:
    > at System.Data.DataColumn.set_DataType(Type value)
    > at TasksDataTier.ReadTasks(DataTable& dt) in
    > c:\code\2.0\gui\code\App_Code\TasksDataTier.cs:line 164
    > at TaskManagerWithCode.ReadTasks() in
    > c:\code\2.0\gui\code\TaskManagerWithCode.aspx.cs:line 31
    > at TaskManagerWithCode.Page_Load(Object sender, EventArgs e) in
    > c:\code\2.0\gui\code\TaskManagerWithCode.aspx.cs:line 20
    > at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,
    > Object o, Object t, EventArgs e)
    > at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object
    > sender, EventArgs e)
    > at System.Web.UI.Control.OnLoad(EventArgs e)
    > at System.Web.UI.Control.LoadRecursive()
    > at System.Web.UI.Page.ProcessRequestMain(Boolean
    > includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    > :
    >
    >
     
    Miha Markic [MVP C#], Feb 18, 2006
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sachin Kulkarni

    DataColumn.Add bug? DataType parameter cannot be added

    Sachin Kulkarni, Feb 4, 2004, in forum: Microsoft ADO .NET
    Replies:
    4
    Views:
    338
    Guest
    Feb 4, 2004
  2. Trygve Lorentzen

    DataSet (DataColumn) datatype WRONG!

    Trygve Lorentzen, Oct 6, 2004, in forum: Microsoft ADO .NET
    Replies:
    1
    Views:
    302
    Trygve Lorentzen
    Oct 6, 2004
  3. Programatix
    Replies:
    1
    Views:
    340
    Miha Markic [MVP C#]
    Jan 30, 2005
  4. George

    Changing DataCOlumn DataType

    George, Mar 21, 2005, in forum: Microsoft ADO .NET
    Replies:
    3
    Views:
    1,565
    Miha Markic [MVP C#]
    Mar 22, 2005
  5. Benton
    Replies:
    3
    Views:
    1,130
    Rick Elbers
    Dec 20, 2005
Loading...

Share This Page