A
Ash.22
Guest
So I am trying to:
1. Generate random character strings (doesn't matter how long each string is) - let's call it random ID
2. Insert them into an access table during insertion of data from another source.
I kind of know how to do number 2, I used to know how to do number 1 but can't wrap my head around it now lol
I have a question, though:
I currently have 32k rows in a table and I might have over a hundred thousand rows. How do I make sure that there will never be duplicates of random ID? Data is inserted on different times and days.
I decided to use cryptoservice and it's only inserting 0 to my database. Here's my code:
Public Sub SendToTempTable()
Dim byt As Byte() = New Byte(4) {}
Dim rngCrypto As New RNGCryptoServiceProvider()
rngCrypto.GetBytes(byt)
Dim randomNumber As Integer = BitConverter.ToInt32(byt, 0)
Try
Using con As New OleDb.OleDbConnection(ObjectBase.ConnectionString)
Using insertCommand As New OleDb.OleDbCommand(Me.InsertCom1, con)
insertCommand.Parameters.Add("@UploaderEID", OleDb.OleDbType.VarChar, 50, "UploaderEID")
insertCommand.Parameters.Add("@DateUploaded", OleDb.OleDbType.Date, 50, "DateUploaded")
insertCommand.Parameters.Add("@DealName", OleDb.OleDbType.VarChar, 50, "DealName")
insertCommand.Parameters.Add("@Industry", OleDb.OleDbType.VarChar, 50, "Industry")
insertCommand.Parameters.Add("@Workstream", OleDb.OleDbType.VarChar, 50, "Workstream")
insertCommand.Parameters.Add("@Tower", OleDb.OleDbType.VarChar, 50, "Tower")
insertCommand.Parameters.Add("@DateOfData", OleDb.OleDbType.Date, 50, "DateOfData")
insertCommand.Parameters.Add("@WeekBeginning", OleDb.OleDbType.Date, 50, "WeekBeginning")
insertCommand.Parameters.Add("@Metric", OleDb.OleDbType.VarChar, 50, "Metric")
insertCommand.Parameters.Add("@MetricValue", OleDb.OleDbType.VarChar, 50, "MetricValue")
insertCommand.Parameters.Add("@Format", OleDb.OleDbType.VarChar, 50, "Format")
insertCommand.Parameters.Add("@Multiplier", OleDb.OleDbType.VarChar, 50, "Multiplier")
insertCommand.Parameters.Add("@MultiplierValue", OleDb.OleDbType.VarChar, 50, "MultiplierValue")
insertCommand.Parameters.Add("@Waived", OleDb.OleDbType.VarChar, 50, "Waived")
insertCommand.Parameters.Add("@checker", OleDb.OleDbType.VarChar, 100, "checker")
insertCommand.Parameters.Add("@CurrentUploader", OleDb.OleDbType.VarChar, 40).Value = Environment.UserName
insertCommand.Parameters.Add("@DateTimeUploaded", OleDb.OleDbType.Date, 40).Value = DateTime.Now
insertCommand.Parameters.Add("@RandomID", OleDb.OleDbType.Integer, 100).Value = randomNumber
Using da As New OleDb.OleDbDataAdapter()
da.InsertCommand = insertCommand
da.Update(Me.DataTable)
End Using
End Using
End Using
Catch ex As Exception
Throw
End Try
End Sub
Any ideas?
Continue reading...
1. Generate random character strings (doesn't matter how long each string is) - let's call it random ID
2. Insert them into an access table during insertion of data from another source.
I kind of know how to do number 2, I used to know how to do number 1 but can't wrap my head around it now lol
I have a question, though:
I currently have 32k rows in a table and I might have over a hundred thousand rows. How do I make sure that there will never be duplicates of random ID? Data is inserted on different times and days.
I decided to use cryptoservice and it's only inserting 0 to my database. Here's my code:
Public Sub SendToTempTable()
Dim byt As Byte() = New Byte(4) {}
Dim rngCrypto As New RNGCryptoServiceProvider()
rngCrypto.GetBytes(byt)
Dim randomNumber As Integer = BitConverter.ToInt32(byt, 0)
Try
Using con As New OleDb.OleDbConnection(ObjectBase.ConnectionString)
Using insertCommand As New OleDb.OleDbCommand(Me.InsertCom1, con)
insertCommand.Parameters.Add("@UploaderEID", OleDb.OleDbType.VarChar, 50, "UploaderEID")
insertCommand.Parameters.Add("@DateUploaded", OleDb.OleDbType.Date, 50, "DateUploaded")
insertCommand.Parameters.Add("@DealName", OleDb.OleDbType.VarChar, 50, "DealName")
insertCommand.Parameters.Add("@Industry", OleDb.OleDbType.VarChar, 50, "Industry")
insertCommand.Parameters.Add("@Workstream", OleDb.OleDbType.VarChar, 50, "Workstream")
insertCommand.Parameters.Add("@Tower", OleDb.OleDbType.VarChar, 50, "Tower")
insertCommand.Parameters.Add("@DateOfData", OleDb.OleDbType.Date, 50, "DateOfData")
insertCommand.Parameters.Add("@WeekBeginning", OleDb.OleDbType.Date, 50, "WeekBeginning")
insertCommand.Parameters.Add("@Metric", OleDb.OleDbType.VarChar, 50, "Metric")
insertCommand.Parameters.Add("@MetricValue", OleDb.OleDbType.VarChar, 50, "MetricValue")
insertCommand.Parameters.Add("@Format", OleDb.OleDbType.VarChar, 50, "Format")
insertCommand.Parameters.Add("@Multiplier", OleDb.OleDbType.VarChar, 50, "Multiplier")
insertCommand.Parameters.Add("@MultiplierValue", OleDb.OleDbType.VarChar, 50, "MultiplierValue")
insertCommand.Parameters.Add("@Waived", OleDb.OleDbType.VarChar, 50, "Waived")
insertCommand.Parameters.Add("@checker", OleDb.OleDbType.VarChar, 100, "checker")
insertCommand.Parameters.Add("@CurrentUploader", OleDb.OleDbType.VarChar, 40).Value = Environment.UserName
insertCommand.Parameters.Add("@DateTimeUploaded", OleDb.OleDbType.Date, 40).Value = DateTime.Now
insertCommand.Parameters.Add("@RandomID", OleDb.OleDbType.Integer, 100).Value = randomNumber
Using da As New OleDb.OleDbDataAdapter()
da.InsertCommand = insertCommand
da.Update(Me.DataTable)
End Using
End Using
End Using
Catch ex As Exception
Throw
End Try
End Sub
Any ideas?
Continue reading...