Changing the Datatype of Datatable Column

  • Thread starter Kevin Humphreys
  • Start date
K

Kevin Humphreys

Hi,
I need to change the Datatype of Datatable Column when the dataset populates
the Datatable
I would like to be able to do this either after the datatable is assigned to
the dataset or
before this happens.

E.G. Convert datatype from Int to String

Below I want to change the first column to string.

myTable = ds.Tables("Table1")
For Each dr1 As DataRow In myTable.Rows
dr1(0) = "Hi"
Next

This will fail because dr(0) is set to int

Thanks In Advance,
Kevin.
 
E

Eliyahu Goldin

Kevin,

This sort of things is rather unusual. May by you want to set the string
value in the datagrid cell rather than in the data source table? That would
be a common thing.

Eliyahu
 
K

Kevin Humphreys

Eliyahu,
That method would be good too.
How can I do this in VB.NET? Im using an unbound datagrid and doing

DataGrid1.DataSource = ds.Tables("Table1")
DG_DataGrid1.DataBind()

when the datatable is populated.
Are you sayining change to a string value when the databind happens or
before? if so then how?

Thanks,
Kevin.
 
E

Eliyahu Goldin

Kevin,

You should use datagid's ItemDataBound event. The event fires for every item
(row) after it gets bound. You get a reference to the item as an event
handler call parameter. Filter out the header, footer etc items (ItemType
propertu) and use Cells collection to get to the cell values. They are all
strings. You can read and set them as required.

Eliyahu
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top