Reputation:
Today, I have problem when create random ID with Guid type in C#.
When I want random ID. And I use:
obj.ID = new Guid(txtID.Text); //ID type Guid
But when run program. It automatic generate 1 id random when I swipe card.
I want when swipe card. It will random ID and retain this values until I delete it.
Edit: My english not good. Sorry about that.
Here my code generate Guid and set value to textbox:
mReader.CurrentCardIDBlock1 = System.Guid.NewGuid().ToString("N");
mReader.CurrentCardIDBlock2 = System.Guid.NewGuid().ToString("N");
txtID.Text = mReader.CurrentCardIDBlock1.ToString();
String strCompont = txtID.Text;
onWriteDataBlock1(strCompont); //Write data to mifare card in block 1 sector 14
MessageBox.Show("Write data success");
If swipe card 1
> random id[any value]
.
Continues swipe card 1
> random id[any value]
. => incorrect
.
I want swipe card 1
> random id[value 1]
, if I take card leave RFID reader and put again.
It until return values is random id[value 1]
in card 1
for me.
Swipe card 2
> random id[any value]
. Swipe card 3
> random id[any value]
. => It's ok.
I think this easy to imagine. Thanks to @Preston Guillot.
Thank you!!!
Upvotes: 1
Views: 59
Reputation: 976
Just use Guid.NewGuid() instead explicit instanciation, it will generate 99.9 % unique ID.
Upvotes: 2