DataColumn.Add bug? DataType parameter cannot be added

  • Thread starter Sachin Kulkarni
  • Start date
S

Sachin Kulkarni

I am trying to create a DataColumn with Name and DataType parameters.
As I understand from the documentation, one of the overloads supports
creation of a column with these two parameters. When I tried
folllowing, however I get error saying

'int' denotes a 'class' where a 'variable' was expected

code
-------
DataColumn dc = new DataColumn("Name", System.Int32)

or

DataColumn dc = new DataColumn("Name",
System.Type.GetType(System.Int32))

or

MyTable.Columns.Add("Name", System.Int32)

ERROR:
-------
'int' denotes a 'class' where a 'variable' was expected


I am using .NET Framework 1.1 in Visual Studio.NET environment. Is
this a bug or am I doing something wrong
 
W

William Ryan eMVP

Sachin:

I only have 1.2 Framework in front of me, but if I take your code and wrap
the GetType("System.Int32") in quotes, it works fine. Similarly, if I get
the type....
int32 myType;
Type t = int32.GetType();
and use t in the constructor, it's works as well.
 
G

Guest

Ok

I can't do Int32.GetType(
Columns.Add("Name", System.Int32) still doesn't wor

but the good news is

Columns.Add("Name", System.Type.GetType("System.Int32")) DOES work !

My have had tried this option as well but only without Namespace - GetType("Int32") which didn't work.

Thanks a lo

----- William Ryan eMVP wrote: ----

Sachin

I only have 1.2 Framework in front of me, but if I take your code and wra
the GetType("System.Int32") in quotes, it works fine. Similarly, if I ge
the type...
int32 myType
Type t = int32.GetType()
and use t in the constructor, it's works as well
 
G

Guest

Hello Sachin

The Following Overloads are provided by the DataColumn Constructor.

1. Initializes a new instance of a DataColumn class
[C#] public DataColumn()

2. Inititalizes a new instance of the DataColumn class using the specified column name
[C#] public DataColumn(string)

3. Inititalizes a new instance of the DataColumn class using the specified column name and data type
[C#] public DataColumn(string, Type)

4. Initializes a new instance of the DataColumn class using the specified name, data type, and expression
[C#] public DataColumn(string, Type, string)

5. Initializes a new instance of the DataColumn class using the specified name, data type, expression, and value that determines whether the column is an attribute
[C#] public DataColumn(string, Type, string, MappingType)

Please note the type of the DataColumn is always passed as an object of type System.Type, Hence it is essential that you use either
1. System.GetType("Fully-Qualified-Name-Of-Type") eg. System.GetType("System.Int32"
2. typeof(TypeName) eg. typeof(System.Int32

to create a System.Type object for the desired type and pass the same to the constructor.


----- Sachin Kulkarni wrote: ----

I am trying to create a DataColumn with Name and DataType parameters
As I understand from the documentation, one of the overloads support
creation of a column with these two parameters. When I trie
folllowing, however I get error sayin

'int' denotes a 'class' where a 'variable' was expecte

code
------
DataColumn dc = new DataColumn("Name", System.Int32

or

DataColumn dc = new DataColumn("Name"
System.Type.GetType(System.Int32)

o

MyTable.Columns.Add("Name", System.Int32

ERROR:
------
'int' denotes a 'class' where a 'variable' was expecte


I am using .NET Framework 1.1 in Visual Studio.NET environment. I
this a bug or am I doing something wron
 
G

Guest

Hello Ryan

Is Int32.GetType() supported ?

How about the typeof operator eg. typeof(System.Int32) ?

Anjoe

----- William Ryan eMVP wrote: -----

Sachin:

I only have 1.2 Framework in front of me, but if I take your code and wrap
the GetType("System.Int32") in quotes, it works fine. Similarly, if I get
the type....
int32 myType;
Type t = int32.GetType();
and use t in the constructor, it's works as well.
 

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