GUID changes from immediate window to table? [modified]
-
My code for storing the data:
If Len(strJnts) > 0 Then \_gblString = CreateGUIDString() gblConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\JWI\\Data\\JWI.mdb;Jet OLEDB:Database Password=jWi;") strData = "INSERT INTO LOLItems (LOLItemsID, LOLIFormID, Type, TextBox, MaterialsID, Units, DateCreated )" \_ & " VALUES ('" & \_gblString & "', " \_ & "'" & \_frmGuid & "', '" \_ & 1 & "',' " \_ & strName & "',' " \_ & \_MATGuid & "',' " \_ & strJnts & "',' " \_ & Now() & "');" gblCMD.Connection = gblConn gblCMD.CommandText = strData Dim cmd As New System.Data.SqlClient.SqlCommand gblConn.Open() gblCMD.ExecuteNonQuery() End If
The value of _MATGuid is gathered from the tag property of a label. In the immediate window: ? _MATGuid "55368562-a5c5-429d-a491-e1bb24f37836" ? strdata "INSERT INTO LOLItems (LOLItemsID, LOLIFormID, Type, TextBox, MaterialsID, Units, DateCreated ) VALUES ('{6b8da5a3-fbad-4140-af9a-2728a9e35af6}', '{a6a0e519-aa21-48b0-b26a-839caed800c7}', '1',' txtRodE_1',' 55368562-a5c5-429d-a491-e1bb24f37836',' 10',' 6/4/2010 9:47:40 PM');" In Access the value for MaterialsID for the record ended up being: {05F3C3FC-D57C-7047-0200-00000000E927} It is a Number field, ReplicationID, Indexed (Duplicates Allowed) When I saved 14 record at a time I got the following- It seems like they are GUIDS being generated by Access as they are so similiar. MaterialsID {05A5C29C-D57C-7047-0500-00000000EA35} {05A5C29C-D57C-7047-0100-000000009A3E} {05A5C29C-D57C-7047-0400-000000001A48} {05A5C29C-D57C-7047-0000-00000000BA28} {05A5C29C-D57C-7047-0200-000000009A30} {05A5C29C-D57C-7047-0200-000000009A43} {05A5C29C-D57C-7047-0400-000000003A34} {05A5C29C-D57C-7047-0000-00000000DA41} {05A5C29C-D57C-7047-0300-000000002A45} {05A5C29C-D57C-7047-0700-000000007A3B} {05A5C29C-D57C-7047-0300-00000000AA31} {05A5C29C-D57C-7047-0500-000000009A49} {05A5C29C-D57C-7047-0600-000000007A39} {05A5C29C-D57C-7047-0100-00000000BA2C} The values that the _MatGuid SHOULD have been are shown below: 55368562-a5c5-429d-a
-
My code for storing the data:
If Len(strJnts) > 0 Then \_gblString = CreateGUIDString() gblConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\JWI\\Data\\JWI.mdb;Jet OLEDB:Database Password=jWi;") strData = "INSERT INTO LOLItems (LOLItemsID, LOLIFormID, Type, TextBox, MaterialsID, Units, DateCreated )" \_ & " VALUES ('" & \_gblString & "', " \_ & "'" & \_frmGuid & "', '" \_ & 1 & "',' " \_ & strName & "',' " \_ & \_MATGuid & "',' " \_ & strJnts & "',' " \_ & Now() & "');" gblCMD.Connection = gblConn gblCMD.CommandText = strData Dim cmd As New System.Data.SqlClient.SqlCommand gblConn.Open() gblCMD.ExecuteNonQuery() End If
The value of _MATGuid is gathered from the tag property of a label. In the immediate window: ? _MATGuid "55368562-a5c5-429d-a491-e1bb24f37836" ? strdata "INSERT INTO LOLItems (LOLItemsID, LOLIFormID, Type, TextBox, MaterialsID, Units, DateCreated ) VALUES ('{6b8da5a3-fbad-4140-af9a-2728a9e35af6}', '{a6a0e519-aa21-48b0-b26a-839caed800c7}', '1',' txtRodE_1',' 55368562-a5c5-429d-a491-e1bb24f37836',' 10',' 6/4/2010 9:47:40 PM');" In Access the value for MaterialsID for the record ended up being: {05F3C3FC-D57C-7047-0200-00000000E927} It is a Number field, ReplicationID, Indexed (Duplicates Allowed) When I saved 14 record at a time I got the following- It seems like they are GUIDS being generated by Access as they are so similiar. MaterialsID {05A5C29C-D57C-7047-0500-00000000EA35} {05A5C29C-D57C-7047-0100-000000009A3E} {05A5C29C-D57C-7047-0400-000000001A48} {05A5C29C-D57C-7047-0000-00000000BA28} {05A5C29C-D57C-7047-0200-000000009A30} {05A5C29C-D57C-7047-0200-000000009A43} {05A5C29C-D57C-7047-0400-000000003A34} {05A5C29C-D57C-7047-0000-00000000DA41} {05A5C29C-D57C-7047-0300-000000002A45} {05A5C29C-D57C-7047-0700-000000007A3B} {05A5C29C-D57C-7047-0300-00000000AA31} {05A5C29C-D57C-7047-0500-000000009A49} {05A5C29C-D57C-7047-0600-000000007A39} {05A5C29C-D57C-7047-0100-00000000BA2C} The values that the _MatGuid SHOULD have been are shown below: 55368562-a5c5-429d-a
First, your values have spaces in them. Second, your GUID in question doesn't have curly brackets around it, possibly making it an invalid GUID. Third, GUIDs are probably overkill for your ID's. Lastly, do NOT use string concatentation to build your SQL statements. Use parameterized queries instead. The parameter objects will handle correctly formatting your values for you instead of you guessing at what they should be and (cardinal sin here) you using values directly out of textboxes completely unvalidated and unnormalized.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
My code for storing the data:
If Len(strJnts) > 0 Then \_gblString = CreateGUIDString() gblConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\JWI\\Data\\JWI.mdb;Jet OLEDB:Database Password=jWi;") strData = "INSERT INTO LOLItems (LOLItemsID, LOLIFormID, Type, TextBox, MaterialsID, Units, DateCreated )" \_ & " VALUES ('" & \_gblString & "', " \_ & "'" & \_frmGuid & "', '" \_ & 1 & "',' " \_ & strName & "',' " \_ & \_MATGuid & "',' " \_ & strJnts & "',' " \_ & Now() & "');" gblCMD.Connection = gblConn gblCMD.CommandText = strData Dim cmd As New System.Data.SqlClient.SqlCommand gblConn.Open() gblCMD.ExecuteNonQuery() End If
The value of _MATGuid is gathered from the tag property of a label. In the immediate window: ? _MATGuid "55368562-a5c5-429d-a491-e1bb24f37836" ? strdata "INSERT INTO LOLItems (LOLItemsID, LOLIFormID, Type, TextBox, MaterialsID, Units, DateCreated ) VALUES ('{6b8da5a3-fbad-4140-af9a-2728a9e35af6}', '{a6a0e519-aa21-48b0-b26a-839caed800c7}', '1',' txtRodE_1',' 55368562-a5c5-429d-a491-e1bb24f37836',' 10',' 6/4/2010 9:47:40 PM');" In Access the value for MaterialsID for the record ended up being: {05F3C3FC-D57C-7047-0200-00000000E927} It is a Number field, ReplicationID, Indexed (Duplicates Allowed) When I saved 14 record at a time I got the following- It seems like they are GUIDS being generated by Access as they are so similiar. MaterialsID {05A5C29C-D57C-7047-0500-00000000EA35} {05A5C29C-D57C-7047-0100-000000009A3E} {05A5C29C-D57C-7047-0400-000000001A48} {05A5C29C-D57C-7047-0000-00000000BA28} {05A5C29C-D57C-7047-0200-000000009A30} {05A5C29C-D57C-7047-0200-000000009A43} {05A5C29C-D57C-7047-0400-000000003A34} {05A5C29C-D57C-7047-0000-00000000DA41} {05A5C29C-D57C-7047-0300-000000002A45} {05A5C29C-D57C-7047-0700-000000007A3B} {05A5C29C-D57C-7047-0300-00000000AA31} {05A5C29C-D57C-7047-0500-000000009A49} {05A5C29C-D57C-7047-0600-000000007A39} {05A5C29C-D57C-7047-0100-00000000BA2C} The values that the _MatGuid SHOULD have been are shown below: 55368562-a5c5-429d-a
Not used Access for some years but IIRC Access will generate values for ReplicaID fields. You should only use this type if you are using replication and have the Replication Manager. As far a I remember without it replication was painful.
Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis The only valid measurement of code quality: WTFs/minute.