M
Masahiro Ito
When using Integer as PK, I would often have functions that would return
the Integer when searching for a specific row in a datatable.
I am trying to switch to GUID. Before, if the function returned a zero, I
would assume the PK didn't exist. Now, if I make a call to lookup the
GUID, and that row doesn't exist yet, I can't seem to figure out the
simplest way - without doing a redundant function to check if exists first
- causing two loops.
Simple Example of my Integer based Code:
Table1 - TableID(Int), Description(Nvarchar)
Private Function GetTableIDByDescription(sDescription as String) as Integer
Private iID as integer = 0
For each row
If Description = sDescription Then iID = Row.TableID
Return iID
Private i as integer = GetTableIDByDescription(id)
If i = 0 then
' New Record - insert
Else
' Use the ID
With GUID?:
Table1 - TableID(GUID), Description(Nvarchar)
Private Function GetTableIDByDescription(sDescription as String) as GUID
Private iID as New Guid ' ??
For each row
If Description = sDescription Then iID = Row.TableID
Return iID
Now, without two functions (one for Exists, one for GetID), is there a way
that I can rewrite all these code sections?
Masa
the Integer when searching for a specific row in a datatable.
I am trying to switch to GUID. Before, if the function returned a zero, I
would assume the PK didn't exist. Now, if I make a call to lookup the
GUID, and that row doesn't exist yet, I can't seem to figure out the
simplest way - without doing a redundant function to check if exists first
- causing two loops.
Simple Example of my Integer based Code:
Table1 - TableID(Int), Description(Nvarchar)
Private Function GetTableIDByDescription(sDescription as String) as Integer
Private iID as integer = 0
For each row
If Description = sDescription Then iID = Row.TableID
Return iID
Private i as integer = GetTableIDByDescription(id)
If i = 0 then
' New Record - insert
Else
' Use the ID
With GUID?:
Table1 - TableID(GUID), Description(Nvarchar)
Private Function GetTableIDByDescription(sDescription as String) as GUID
Private iID as New Guid ' ??
For each row
If Description = sDescription Then iID = Row.TableID
Return iID
Now, without two functions (one for Exists, one for GetID), is there a way
that I can rewrite all these code sections?
Masa