Created
July 25, 2011 19:14
-
-
Save Sheeo/1104920 to your computer and use it in GitHub Desktop.
Not the way to add rows to a table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Shared Function GenerateNewUniqueID() As String | |
Dim returnString As String = Guid.NewGuid.ToString() | |
Dim unique As Boolean = False | |
Using conn As New SqlConnection(My.Settings.onlinePDFConnectionString) | |
conn.Open() | |
Dim commString As String = "SELECT Count(*) FROM Books WHERE UniqueID = '{0}%'" | |
Dim comm As New SqlCommand(String.Format(commString, returnString.Substring(0, 13)), conn) | |
While Not unique | |
comm.CommandText = String.Format(commString, returnString.Substring(0, 13)) | |
Dim count As Integer = comm.ExecuteScalar() | |
If count > 0 Then | |
returnString = Guid.NewGuid.ToString() | |
Else | |
unique = True | |
End If | |
End While | |
End Using | |
Return returnString | |
End Function | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment