|
|
What do you mean with that?
|
|
|
|
|
hello again,
well I made a parent child form in C# 2.0 windows application with sql server 2000 and i'm having troble in deleting the parent record bcz it gives a constraint error that the table is also reffered to in another child table that is not being used in the current form. so can u plz tell me what I should do to delete that parent record when there are references in its child table.
thanks in advance
Rocky
|
|
|
|
|
i have also face the same problem in java.
At that time i have to delete the record from the child record and then to the parent node.
U can't simply delete parent record.
Try this out and let me know.
|
|
|
|
|
This isn't strictly true. You can do a cascading delete, but only if the database supports it and the tables have been set up to support it. I wouldn't recommend it, but you can.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
If some constraints are specified between two tables. How do to overcome the constraints.
If the above sentence is true means. How do you delete the data with deleting the data from the child record.
Regards,
A Jabeer Ali
|
|
|
|
|
It works by setting up a cascading delete on a foreign key. Basically, this means that when you delete from the master table, related entries are deleted from child tables. In SQL Server, you do this by adding ON DELETE CASCADE to the foreign key constraint.
As I noted above though, it is generally best to avoid doing this. You really need to have more control over what you are deleting because sometimes you may end up deleting things that you didn't want to.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
well yes I didnt have the cascade option there but now I think its a better idea to have more control over it bcz these tables are bill and billDetails so one shouldnt be able to delete the whole bill along with all the detail records. Right?
Rocky
|
|
|
|
|
well I have a little question: how do we chk for the existance of child records in C#. is it something like getChildRows() or something??
|
|
|
|
|
You actually need to query the tables that are linked to see if they point back to the row.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
draw an organization chart on a form but the rectangles I drew exced the size of the form what can I do to make the form sizable
merwa
|
|
|
|
|
Look at Form property -> FormBorderStyle
If you can't find time to do it right the first time how are you going to find time to do it again?
|
|
|
|
|
EDIT2: Solved, thanks to CPallini. I was stupid not to see it in the first place myself.
EDIT: The code that generates the random bools is in a different assembly from the code that calls it - caching is unlikely to work. Due to design constraints, I cannot change GetRandomBool's signature
I am trying to generate pairs of bools in a loop. Here's the relevant code with method and variable names changed:
for(int i = 0; i < rounds; i++)
{
bool firstPlayersChoice = GetRandomBool();
bool secondPlayersChoice = GetRandomBool();
}
public static bool GetRandomBool()
{
System.Random randomNumberGenerator = new System.Random((int) DateTime.Now.Ticks);
int randomNumber = randomNumberGenerator.Next();
if(randomNumber % 2 == 1)
{
return true;
}
else
{
return false;
}
}
When I step through the code, executing the program step by step, the results are fine. However, when I run the program directly, I'm seeing pairs of the same value, i.e., many instances of (true, true) or (false, false). Statistically, half my outcomes should be identical pairs, but even when rounds is 100, I barely see a non-identical pair like (true, false).
I'm guessing the program runs so fast that the two calls to GetRandomBool generate identical values for randomNumberGenerator and hence generate identical bools.
Is there some way I can get bool pairs that are statistically similar to what I'd expect?
-- modified at 9:10 Thursday 22nd March, 2007
-- modified at 9:13 Thursday 22nd March, 2007
-- modified at 10:58 Thursday 22nd March, 2007
Cheers,
Vikram.
The cold will freeze our stares
We won't care...
|
|
|
|
|
I think you get the same Ticks twice.
Have you tried re-using the random number generator?
for(int i = 0; i < rounds; i++){
System.Random randomNumberGenerator = new System.Random((int) DateTime.Now.Ticks); bool firstPlayersChoice = GetRandomBool(randomNumberGenerator);
bool secondPlayersChoice = GetRandomBool(randomNumberGenerator);
}
public static bool GetRandomBool(System.Random randomNumberGenerator){
int randomNumber = randomNumberGenerator.Next();
if(randomNumber % 2 == 1)
{
return true;
}
else
{
return false;
}
}
____________________________________
There is no proof for this sentence.
|
|
|
|
|
I think it's a better idea to reuse more times the random generated sequence,
see my posting [^]
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Thanks for the reply, Coco. Unfortunately, I have some constraints - I cannot modify GetRandomBool's signature. You see, it's a method in a different assembly that is called using a superclass reference. I've updated my post to reflect the constraints.
I'd appreciate any help.
Cheers,
Vikram.
The cold will freeze our stares
We won't care...
|
|
|
|
|
You should NOT restart the number generator sequence each time your GetRandomBool is called.
I suggest the following changes:
System.Random randomNumberGenerator = new System.Random((int) DateTime.Now.Ticks);
for(int i = 0; i < rounds; i++)
{
bool firstPlayersChoice = GetRandomBool(randomNumberGenerator);
bool secondPlayersChoice = GetRandomBool(randomNumberGenerator);
}
...
public static bool GetRandomBool(System.Random rg)
{
int randomNumber = rg.Next();
if(randomNumber % 2 == 1)
{
return true;
}
else
{
return false;
}
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Thanks for the reply, mate. Unfortunately, I have some constraints. Please see my original post (I've updated it). Would appreciate assistance.
Cheers,
Vikram.
The cold will freeze our stares
We won't care...
|
|
|
|
|
You're going to have to introduce a waitstate into your call then. Every call to GetRandomBool() made before the system ticks will return the same value since you're reinitializing the RNG to the same starting value. IIRC the tick is a legacy timer that only updates ~18x per second. The highest resolution timer you can get will report in milliseconds but only actually updates every 10-30ms (depends on machine, may vary more with ones I didn't test on). If you can't change GetRandomBool() and need more than 18 returns per second you're SOL.
--
CleaKO The sad part about this instance is that none of the users ever said anything [about the problem].
Pete O`Hanlon Doesn't that just tell you everything you need to know about users?
|
|
|
|
|
If your constraint applies only to the function signature then modifty its body as follows:
static System.Random _randomNumberGenerator = new System.Random((int)DateTime.Now.Ticks);
public static bool GetRandomBool()
{
int randomNumber = _randomNumberGenerator.Next();
if(randomNumber % 2 == 1)
{
return true;
}
else
{
return false;
}
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Your solution is so simple, it's beautiful. 5'd.
You'll get your mention in the upcoming article, CPallini.
Cheers,
Vikram.
The cold will freeze our stares
We won't care...
|
|
|
|
|
Vikram A Punathambekar wrote: Your solution is so simple, it's beautiful. 5'd.
Thanks.
Vikram A Punathambekar wrote: You'll get your mention in the upcoming article, CPallini.
Thanks again.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
The Random object initialises itself with a value from the System Time so most of the time you're going to get the same value. occasionally the clock will tick over between calls. This seems to be the behaviour you're getting.
If i'm using random I tend to add it as an instance variable or as a public static variable of another class and call getNext() without resetting it.
I found this problem out the hard way and had to ask the good people on CP at the time.
Russ
|
|
|
|
|
Thanks for the reply, Russell. Unfortunately, I have some constraints. Please see my original post (I've updated it). I'd appreciate your assistance.
Cheers,
Vikram.
The cold will freeze our stares
We won't care...
|
|
|
|
|
As there's no chance to alter GetRandomBool(), you might insert a delay:
bool firstPlayersChoice = GetRandomBool();
Thread.Sleep(1);
bool secondPlayersChoice = GetRandomBool();
Any questions about the program being slow can be redirected to the author of GetRandomBool().
____________________________________
There is no proof for this sentence.
|
|
|
|