Adding a column to a datatable

T

Tina

I'm doing this...

Dim dt As New DataTable

dt.Columns.Add("AreaGroup", Type.GetType("System.String"))

dt.Columns.Add("Col1", Type.GetType("System.String"))

dt.Columns.Add("Col2", Type.GetType("System.decimal"))

it works ok when I specify System.String but when I specify System.decimal I
get an exception saying...

'dataType' argument cannot be null. Parameter name: dataType

Why?
T
 
T

Teemu Keiski

Hi,

not sure if it is case-sensitive but type name is "System.Decimal" (Decimal
with the first character in uppercase)
 
Joined
May 7, 2012
Messages
1
Reaction score
0
Answer

"Tina" <[email protected]> wrote in message
news:[email protected]...
> I'm doing this...
>
> Dim dt As New DataTable
>
> dt.Columns.Add("AreaGroup", Type.GetType("System.String"))
>
> dt.Columns.Add("Col1", Type.GetType("System.String"))
>
> dt.Columns.Add("Col2", Type.GetType("System.Decimal"))
>
> it works ok when I specify System.String but when I specify System.decimal
I
> get an exception saying...
>
> 'dataType' argument cannot be null. Parameter name: dataType
>
> Why?
> T
>Answer []:
Keep first letter capital
eg: System.Decimal
System.Double

This will make your code work:congrats:

Thanks
Siid.
 

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

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top