[2005] column datatype for built-in-memory-datatable problem
I need to build a new table in memory that has two columns. Each will contain a from a different database (well one's a read in XML dataset) It's basically a table to translate the former primary key to the new primary key while the XML file gets imported into the Access database. So I need the datatype on both columns to be string. If I just make it and add data like this:
Code:
Dim temptable As New DataTable
temptable.Columns.Add("one")
temptable.Columns.Add("two")
Dim temp(1) As String
temp(0) = "fish"
temp(1) = "cow"
temptable.rows.add(temp)
what will it do? Will it convert fish and cow to some wacky general object datatype and append stuff to it or put the value literally in double quotes or will it automatically change the column datatype to string or will it just crash saying I haven't specified a datatype yet or something?
By the way, I'm adding columns with the simplest overload because I can't figure out how the heck to write the second part for the one where it's column name then datatype. You'd think it would be System.Data.DataColumn.DataType.string like the popup window suggests but nope :(
Re: [2005] column datatype for built-in-memory-datatable problem
Quote:
Originally Posted by Desolator144
By the way, I'm adding columns with the simplest overload because I can't figure out how the heck to write the second part for the one where it's column name then datatype. You'd think it would be System.Data.DataColumn.DataType.string like the popup window suggests but nope :(
I'm sorry, what? You can't work out how to specify the type when the documentation provides this code example:
Quote:
Originally Posted by MSDN
vb.net Code:
Private Sub AddColumn()
Dim columns As DataColumnCollection = _
DataSet1.Tables("Orders").Columns
' Add a new column and return it.
Dim column As DataColumn = columns.Add( _
"Total", System.Type.GetType("System.Decimal"))
column.ReadOnly = True
column.Unique = False
End Sub
I can only assume that that means that you didn't actually bother to read the documentation.
That said, there's a simpler way still. That code could be rewritten like this:
vb.net Code:
Private Sub AddColumn()
Dim columns As DataColumnCollection = _
DataSet1.Tables("Orders").Columns
' Add a new column and return it.
Dim column As DataColumn = columns.Add( _
"Total", GetType(Decimal))
column.ReadOnly = True
column.Unique = False
End Sub
GetType is a VB.NET operator that gets a System.Type object from a data type. A Type object is an instance of the Type class that represents a data type. In that code the data type is Decimal and GetType returns a Type object that represents that type.
Re: [2005] column datatype for built-in-memory-datatable problem
well first of all, that's the worst method name ever. In fact, that's the dumbest method ever. The way they named it, you "get the type" of a system type and it returns a system type. If I didn't know better I'd say the method actually does nothing lol. But thanks for the answer :D
And btw I've found a useful answer in the MSDN library like 1% of the time so I go there as a last resort. Once in a great while I'll check it for something really general that I know is in there or a good description of a method or something.