Is it possible to set a datacolumn's datatype by using a string value?

  • Thread starter Thread starter Benton
  • Start date Start date
B

Benton

Hi there,

I want to create some DataColumns using the following approach:

string datatype = "int";

DataColumn intCol = new DataCoulmn();
intCol.DataType = typeof(datatype);

string datatype = "string";

DataColumn strCol = new DataCoulmn();
strCol.DataType = typeof(datatype);

I know it doesn't work quite like this, but, is there a way to accomplish
what I am trying to do?

Best Regards,

-Benton
 
Hi,

try using Type.GetType(string typename);


string datatype = "System.String";

DataColumn strCol = new DataColumn();
strCol.DataType = Type.GetType(datatype);
 
You can also use

DataColumn strCol = new DataColumn();
strCol.DataType = typeof(string);

no quotes
 
Benton,


Design technically you are extending the DataColumn with something
like

public void SetDataType(string DataType as string)

or overloading the property DataType( which isnt possible).

Certainly the way to go if you are planning to add more functionality
or overrides to the DataColumn



Rick
 

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

Back
Top