Link to home
Create AccountLog in
Avatar of jgerbitz
jgerbitzFlag for Canada

asked on

Question about adding DataColumn to DataTable

Hi,

I am trying to add DataColumns to a DataTable in c# (vs 2005):

dtAddPatient.Columns.Add("dcPatientLastName", System.Type.GetType("System.String"));

The whole line is underlined.  There are 2 errors:
1) When hovering over the column name: Argument '1': Cannot convert from 'System.Data.DataColumn' to 'string'.
2) When hoving over the rest of the line: The best overloaded method match for 'System.Data.DataColumnCollection.Add(string, System.Type)' has some invalid arguments.

I've seen it done like this elsewhere, so I don't have an idea what I'm doing wrong.
Appreciate any help!
Avatar of DotNetThinker
DotNetThinker
Flag of United States of America image

dtAddPatient.Columns.Add("dcPatientLastName", typeof(string));

...that should do it
Avatar of jgerbitz

ASKER

Thanks, but still getting the same errors.
ASKER CERTIFIED SOLUTION
Avatar of DotNetThinker
DotNetThinker
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Yikes... my fault: the format in my original post worked, but the error isn't removed until I actually rebuild the solution.  I'm new to C#... in VB.NET the design-time errors were removed right away without having to rebuild.
Anyway, it seems to be working.  I'll give you the points for trying to help out.
Thanks