|
-
Oct 25th, 2024, 12:27 PM
#1
Datatable Data Types
This thread is related to this other thread:
https://www.vbforums.com/showthread....nge&highlight=
In that other thread, my issue was that WriteXML was writing a bunch of type information for GUID fields, and that type information appeared to be specific to the .NET version...to some extent, such that a GUID exported from .NET 8 via XML was not the same as a GUID imported by Framework.
The solution was in the final post of that thread, but it turns out to have been a bit stranger than I realized.
The dataset being exported has half a dozen tables, all of which have at least one GUID fields and some have up to six or seven. For all of the tables, the PK is a GUID, but there are usually non-PK fields that are GUIDs, as well.
What I have found is that some GUID fields will import, but others will not, and it isn't consistent. Each export is a survey, and all the different items that hang off that survey. All surveys have the same schema, just different data, and different numbers of rows in child tables. What I am seeing is that some surveys import fine, and for others, some GUID fields come across as Nulls. If that happens for a field that is a PK, or any other non-nullable field, that's a disaster.
So, the solution in the other thread was that I created the target dataset, which I did with a series of statements like this:
Code:
da.SelectCommand.CommandText = " SELECT * FROM STRM_Survey_Waypoints WHERE 1=0"
da.Fill(existingDS, "STRM_Survey_Waypoints")
Basically, I was just getting an empty table. Looking at the columns in this table, they were properly identified. The PK was type GUID, and so forth for all other columns in the table. Of course, this table was one of the ones where I got nulls for the PK.
My first thought was to create the table directly, rather than through a query, such that I could control the types. This is tedious, but possible:
Code:
Dim dt As New DataTable("STRM_Survey_Waypoints")
Dim col = New DataColumn("WaypointID", GetType(Guid))
col.AllowDBNull = False
dt.Columns.Add(col)
dt.Columns.Add(New DataColumn("SurveyID", GetType(Guid)))
'.etc, several more columns
At first, I made the WaypointID a string, which worked...except that the field was a string, when it needed to be a GUID.
I then changed to the code shown, where it IS a GUID, and it still worked.
So, if I created the table by querying the DB where WaypointID is a GUID, the datatable has the type for the WaypointID column as a GUID, but all incoming Waypoints come in as Null. If I create the table directly, as shown, while setting the column type as GUID and not nullable, then it works fine.
That means that I can solve this with the tedious process of creating every table by hand, but I'm trying to understand WHY creating it by hand as a GUID works, while creating it via querying the underlying table does not always work (most fields work, and all fields work for some surveys, but not all).
Any suggestions?
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|