Home All Groups Group Topic Archive Search About

2.0 : DataColumn.DataType

Author
17 Feb 2006 7:13 PM
John A Grandy
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)
Show quote
:

Author
18 Feb 2006 8:05 AM
Miha Markic [MVP C#]
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/

Show quote
"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:O4yqIZ$MGHA.3164@TK2MSFTNGP11.phx.gbl...
>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)
> :
>
>

AddThis Social Bookmark Button