|
Why do people insist on this anti-pattern?
You will likely need to persist all the id's in a table, then just create random number, check for uniqueness on table, repeat if necessary, add newly created number. For concurrency, you will probably need to lock the table or something.
|
|
|
|
|
leppie wrote: Why do people insist on this anti-pattern? [Frown]
hmm didnt get that one! honestly.
now comming to the point. I really dont think locking a table would be a great idea from an ASP .NET app. I may be wrong. Do u think I can generate the random numbers from TSQL?
Rocky
Success is a ladder which you can't climb with your hands in your pockets.
|
|
|
|
|
|
yea well I had that in mind too but how will I convert that to a six digit number?
Rocky
Success is a ladder which you can't climb with your hands in your pockets.
|
|
|
|
|
Ohh sorry. I haven't noticed the 6 digit requirement. You need follow what leppie said then. It will tough to make it reliable.
|
|
|
|
|
no its ok, but I'm still perplexed about locking the table from this asp .net app. I think it has the potential of bring the whole application to its knees!.
Rocky
Success is a ladder which you can't climb with your hands in your pockets.
|
|
|
|
|
It will only lock the table while generating the number, that should take 10ms, so that should work unless you need to do this 100 times a seconds. And in that case 6 digits wont cover uniqueness, you will run out in 10 minutes. That's why it is an anti-pattern (just wrong from the start).
|
|
|
|
|
ok so that explains it!,
thanks
just one more question: hope u can answer that. How can we lock the table from ASP .NET, I've been searching over that as well. Any tips?
Rocky
Success is a ladder which you can't climb with your hands in your pockets.
|
|
|
|
|
The problem of generating non-repeating 6-digit numbers that appear random can be solved with cyclic groups:
Start with any 6-digit number. This is your first key. Pick a random prime number (any will work, but a 6-digit prime between 300000 and 700000 would be best).
Every time you add the prime number to the key (and truncate to six digits), you get the next key. The beauty of this approach is that you'll go through EVERY 6-digit number before it repeats.
|
|
|
|
|
Asp.Net with C# (2.0)
i am just novice user to this Gateway service,
i wants to make enable my user at my site to by items and pay through Visa or master card....
What should be the my first step ?
can you please help me .....
Thanks in advance...
Niraj
|
|
|
|
|
There is an article for a specific gateway on CodeProject, else I have seen an advert sometimes on the bottom of this site for one.
|
|
|
|
|
Find a gateway and set up an account with that bank. Or look into Paypal. IF you use Authorize, I have an article on the site that simplifies using it.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
I need to read a file from the bottom is it possible in c language ?
The exact requirement is
suppose having a file like
========================================
hi
how are you
exit 1
then
you
exit 1
and i can
make this
exit 0
===========================================
I need to read the file from bottom to search the last exit 1
and print the lines above it
the output will be
then
you
Can anybody help me ??
vineesh
|
|
|
|
|
Hello Vineesh,
Trh using the given code snippet. You need to import the namespace System.IO.
using System.IO;
BEGIN CODE
<br />
StreamReader sr = new StreamReader("C:\\Test.txt");<br />
String str;<br />
<br />
str = sr.ReadToEnd();<br />
<br />
int index= str.LastIndexOf("exit 1");<br />
<br />
TextBox1.Text=str.Substring(0,index);<br />
END CODE
I hope this will meet your requirement.
Regards,
Allen
Allen Smith
ComponentOne LLC
www.componentone.com
|
|
|
|
|
hi,
File.ReadAllBytes returns a byte array which can be then used the way you want to play with it.
Regards.
Atif Ali Bhatti.
|
|
|
|
|
Thanks .. It works
vineesh
|
|
|
|
|
i have problems like this. i cannot close forms in tabpage when i clear tabpage. i found this code but it doesnt work absaloutly. that code close only forms in fisrt tabpage but not in others tabpages(for exmp. tabpage2, tabpage3, etc.)
code is that:
List<Form> forms = new List<Form>();
foreach (Form f in Application.OpenForms)
if (f.Handle != Form1.ActiveForm.Handle)
forms.Add(f);
foreach (Form f in forms)
f.Close();
|
|
|
|
|
You want to close forms that are embedded inside tabs ? Isn't that counterintuitive ?
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
to close all forms that embedded in tabpage more. how can i do?
i can close only one form but i want all form close which opened.
|
|
|
|
|
to close all forms that embedded in tabpage more. how can i do?
i can close only one form but i want all form close which opened.
|
|
|
|
|
I'm trying to develop a forumn page like code project's. The client-side expand and collapse function is what is attractive to me. I've noticed the main property that makes the client-side code work is that all hyperlink ID's are set to the name: id=DynMessLink.
The problem is that asp hyperlink IDs cannot be the same name but I need the databinding functionality for setting the text property.
Any ideas?
"Make it as simple as possible, but no simpler" Issac Newton
|
|
|
|
|
Emit a javascript array with all the id's, pass that to the client-side code.
|
|
|
|
|
In my application I have an array of custom objects that I want to search by one of the properties of the custom object (the ID property which is an int), please see the code below to understand what I'm trying to do:
private CustomObject[] _customObjects;
public CustomObject CustomObjects
{
get
{
if(_customObjects == null)
{
CustomObject[] customObjects = CustomObject.GetCustomObjects();
Array.Sort(customObjects);
_customObjects = customObjects;
}
}
public IsIDInList(int id)
{
return Array.BinarySearch(CustomObjects, id) >= 0;
}
I could use a dictionary of course but I don't want to for some reasons specific to my application. Any suggestions are highly appreciated...
|
|
|
|
|
Hi,
I suggest you have a look at this overload:
Array.BinarySearch Method (Array, Int32, Int32, Object, IComparer)
and if necessary read up on IComparer.
|
|
|
|
|
Hi, thanks for your reply, actually I know about IComparer and IComparable and I use them very often in my code but I never had the need to compare objects of different types, this is why I'm a little confused, I know it's not possible using the generic version of IComparer, are you referring to the non-generic version? A short code sample would very helpful, thanks a lot.
|
|
|
|