|
use an absolute or relative path. I expect the issue is that your path is not right from the context of the page using it.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
i want to create a random number when i insert a record to table. and i want that random number is unik and it not be more than 10 digit. i should use a GUID or ....? can any bode give me a suggestion and good idea?
thanks.
|
|
|
|
|
ptvce wrote: i should use a GUID or ....?
Yes, you can use GUID.
cheers,
Abhijit
CodeProject MVP
|
|
|
|
|
I'm not sure a GUID satisfies this requirement - "and it not be more than 10 digit".
Scott
|
|
|
|
|
I've done this in the past by creating guids in a loop until xx characters of the GUID are unique in the DB.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Why not use a identity column? It can auto increment the value upon each insertion.
|
|
|
|
|
System.Random r = new System.Random();
string strrnd = (100000 + r.Next(799999)).ToString();
|
|
|
|
|
But it doesn't guarantee to be unique always.
|
|
|
|
|
Yes.. Navaneeth is right.. .If you cannot deal with GUID field (36 characters in size)
I think best way for uniqueness is to leave this to SQL server using Identity.
|
|
|
|
|
You can take several approaches:
Make a list of max number of random numbers that you need and shuffle them, then go and insert one after another. A good random shuffle algorithm you can create in no time.
You could use a good hash function. There are plenty to choose. You need two keys, one is secret and somewhat random, and another is ID itself. You combine them and get a random number using the hash function. (I can give you an example of very simple and fast one if you like.)
Another is to create a circular random function which calculates a random number from the previous random value. You keep only the last entry. You take care that the cycle size is exactly what you need.
You use normal random number and check if that one is used in the database, and keep searching for the one that is not.
You can use a simple random number and attach to it your ID so that the size of both is 10 digit. For example you know you will not need more than 9999 id's. Good. Take six digit random number and concatenate to it 4 digit ID. This is not a completely random number but it is as strong as six digit random number.
You can use a matrix
0123456789
0
1
2
3
4
5
6
7
8
9
and then use random generator mod 10 (0-9 digit at random) (or in general mod matrix size). Now ,if you would get these numbers 4, 5, 7, 0 you mark (4,5) (5,7) (7,0) and keep on until you get your first ten-digit number. For the next ten-digit number you keep on marking but you count how many entries were previously already marked. If you find for a 10 digit number that its all 9 entries were marked you reject that number. This way you get a smaller number of unique random numbers, but the matrix can always be larger (100x100...), of course.
Keep in mind what security level you need.
And do not use GUID, it is never a random number on one computer.
modified on Monday, March 9, 2009 2:02 PM
|
|
|
|
|
Perisic, Aleksandar wrote: And do not use GUID, it is never a random number on one computer.
what do you mean? Are you implying you can generate the same GUID in one computer? Huh!
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
Really, how did you get to this "Are you implying you can generate the same GUID in one computer?"
I said GUID is never a random number on one computer. Random. Use a GUID tool available out there and see for yourself.
GUID is not used to create a random number. It is used only to create a unique number.
For a GUID on one computer, several parameters are used (some of which are fixed some are dynamic) like netwok card ID, current time, etc.... so that when they are combined it is almost impossible to create the same GUID ever again during the time of the entire Universe (yes, that unique). Not random. Unique.
Now once this number is created, if you keep asking for another one on the same machine, you get numbers that are very close to each other, sometimes even in increasing order. Random? Not even close.
GUID could be taken maybe as somewhat random (or better say unpredictable) if you have computers in a network and then you take one time one GUID from each. Even then that is only one series with some form of randomness that you can get. But even a network card ID, time etc that are combined in a GUID have some format, so no, a GUID is really not random in any sense and should never be used as such unless a developer really need some form of "unknown, unpredictable number".
|
|
|
|
|
Perisic, Aleksandar wrote: Really, how did you get to this "Are you implying you can generate the same GUID in one computer?"
I said GUID is never a random number on one computer. Random. Use a GUID tool available out there and see for yourself.
I've to re-read your message again and I guess I missed "never" in your statement. May be, you know, Day Light Saving (Summer Time) changed yesterday and I am still under the weather. Sorry for the mix up.
I know GuiD are not random, they are pseudo random.
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
As you wish but:
A GUID is a 128-bit integer (16 bytes) that can be used across all computers and networks wherever a unique identifier is required. Such an identifier has a very low probability of being duplicated.
A GUID has nothing in common with random numbers, it is as random as credit card number is random. You will probably not guess the number of my credit card but it is still not random, it is a structured number with very specific parts. The similar way GUID has structure and is not random.
A GUID can be based on a random generator, but we do not know wheather it is or not, and GUID library support on Microsoft
OS is not, so we should not use it for creating randomness.
However, if the size cost is acceptable, creating unique numbers using GUID's is a good solution, especially knowing that it is unique in the Universe so we can move around records and we will never find two objects with the same ID.
|
|
|
|
|
I want to change color of the windows title bar so that it blinks when it is not focused i.e. it is minimized in the task bar. I want to achieve it when a new message arrives. I m using a web form and thus window is a browser window.Thanks in advance!!!
|
|
|
|
|
Between operating system issues, browser issues and security issues -- not to mention user annoyance issues -- I don't think this is possible.
|
|
|
|
|
How to use updatePanel without ScriptManager in ASP.NET. Is it possible to use it without ScriptManager
|
|
|
|
|
hey....
scriptManager is a server control that includes all the necessary javascript that the page needs to run the update panel. Update panel needs script manager as it is defined as mandatory in compiler. otherwise we may include all the javascript files it needs manually without including scriptmanager.
I dont think it is possible to use UpdatePanel without ScriptManager. In case you really need, create the updatepanel yourself..
|
|
|
|
|
yes, you'll create user control.
|
|
|
|
|
Jack Li wrote: yes, you'll create user control.
What does it mean?
cheers,
Abhijit
CodeProject MVP
|
|
|
|
|
Any specific reason, you dont want to use scriptmanager ?
If you have more then 2 pages with scripmanager and it is giving you error when you try to use both the pages, then you can use ScriptManagerProxy in one of the page. Or you can add the ScriptManager in the "Master Page", and in all the content page you will able to use it.
Or you can use other 3rd party framework.
|
|
|
|
|
Hi!
I work with C #
I want update my columns in my GridView without going through edit :
for each row I click update button to update the line
how? Thank you.
|
|
|
|
|
I am not sure what you want. How can you update with out editing? If you want to read from updated data then you can do it, but someone has to update the data somehow in the first place.
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
Thank you yusuf!
I'm sorry I speak badly English.
in place of the method edit update cancel I want :
having a button for each row of the GridView and if I click on this button I will update the line.
|
|
|
|
|
Hi,
when you are projecting data to gridview ,pass the column id also (ex:if you projecting user info to gridview,then you can pass the user id also as invisble to end user) and by using that id at the runtime you can update the particular row...
|
|
|
|