I am trying to populate a column in a database with unique strings. How do I achieve this?
My current code just calls the same instance of the GetUniqueKey()
method so it just generates the same key. This method will only be run once. Like I said, I am trying to generate a unique key for each row. The GetUniqueKey()
method generates an alphanumeric string. How do I calla new instance of Hash.GetUniqueKey()
in order to get a new unique key?
private readonly int KEY_SIZE = 5;
public void Fill() {
connectionStringBuilder.InitialCatalog = "parts";
connection.ConnectionString = CONSTANTS.connStringParts;
string query = @"UPDATE parts SET [InternalID] = '" + Hash.GetUniqueKey(KEY_SIZE) + "'";
SqlCommand command = new SqlCommand(query, connection);
using(connection) {
try {
connection.Open();
command.ExecuteNonQuery();
connection.Close();
}
catch(Exception ex) {
MessageBox.Show(Resource1.DatabaseConnectionError, Resource1.Error, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}