2.0 : DataColumn.DataType

J

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)
:
 
M

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);
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top