|
I'm using DataAdapter.Fill() in my ASPX code. It takes rather long time to be completed and if I refresh page in IE causing thereby second invocation of .Fill() I get the following exception:
There is already an open DataReader associated with this Command which must be closed first
How can I fix this error?
|
|
|
|
|
One DataReader per one connection.
When you refresh, another readers is instantiated for the fill method and the same connection is used and thus exception is thrown.
|
|
|
|
|
Don't do that.
Check to see if it's already filling before trying to fill?
Cancel the existing fill operation?
|
|
|
|
|
Ok, how can I do this checking?
|
|
|
|
|
Perhaps check the .IsClosed property?
/ravi
|
|
|
|
|
DataReader is connection based. When a DataReader is opened, it engross the connection till close it.
So, After you use a DataReder, you must close it immediately.
|
|
|
|
|
Hi
You can check with ConnectionState property.
|
|
|
|
|
Is your command object wrapped in a using block?
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
I noticed that in one of my applications, for some odd reason, I could not calculate for angles less than 45 degrees on my form. I created a point of origin at (150,300)- I'll call this Po - and then I use mouse_move to find my second point - Pm - on a form 300x300. As I move closer to the left and right side, my angle just stops at 45, and sadly does not go down. I've added break points to see what values I was coming up with, and even on a calculator, the angles should work out between Po and Pm . Is there a reason this doesn't work? I'll attach my code below. I'll also note that the code I have works specifically so that moving right, the angle is negative and moving left, the angle is positive- this is done for something I'm rotating.
try<br />
{<br />
<br />
if (e.X > 150 && e.X < lastx)<br />
{<br />
curangle = (float)((Math.Atan((300 - e.Y) / (150 - e.X))) * (-180 / Math.PI));<br />
}<br />
else if (e.X > 150 && e.X > lastx)<br />
{<br />
curangle = (float)((Math.Atan((300 - e.Y) / (150 - e.X))) * (180 / Math.PI));<br />
curangle = -180-curangle;<br />
}<br />
if (e.X < 150 && e.X < lastx)<br />
{<br />
curangle = (float)((Math.Atan((300 - e.Y) / (150 - e.X))) * (180 / Math.PI));<br />
curangle = 180 - curangle;<br />
}<br />
else if (e.X < 150 && e.X > lastx)<br />
{<br />
curangle = (float)((Math.Atan((300 - e.Y) / (150 - e.X))) * (-180 / Math.PI));<br />
}<br />
<br />
lastx = e.X;<br />
<br />
lblone.Text = Convert.ToString(curangle + " degrees");<br />
<br />
}<br />
catch (DivideByZeroException)<br />
{<br />
}
Thanks in advance guys
modified on Friday, May 9, 2008 3:37 PM
|
|
|
|
|
To calculate the angle why not just use:
float distanceBetweenPoints = Math.Sqrt(Math.Pow(e.X-150, 2)+Math.Pow(300-e.Y, 2));
float angle = ACos((e.X-150)/distanceBetweenPoints);
angle = angle*(180/Math.PI)
That should give the angle from the horizontal plane, anti-clockwise.
/
/
/
/ This angle here
/______________
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
Thanks! Much appreciated I just had to inverse one thing, but it was so minor and now it works flawless. Thank you for the help ^^!
|
|
|
|
|
Hi
I work with some very large arrays (millions of items) in an algorithm, however, since most fields contains the value 0 I decided to use a Dictionary to represent only the array's fields where the value is not 0.
Dictionary means that the first int is the index of the array in which the value would appear, and the second int is the value of this index.
Now, I have two of these "arrays" that I need to compare. For each _existing_ index I need to find the difference between the arrays.
E.g. index i exists in dict1 (first dictionary) but not in dict2, thus the difference should be the value of dict1[i] alone. index i exists in both dictionaries thus the difference should be dict1[i] - dict2[i].
Now, in theory this should be possible to achieve with iterating each unique index in BOTH dictionaries only once (e.g. if an index occurs in both dictionaries it should only be iterated once)
My suggestion was that I start by getting the first item from each and compare the index of these.if they are equal I would increase both iterators.if one is higher than the other I would increase the iterator until they are equal or the other one is lower. This would be repeated until both are iterated through. Any ideas how I can do this with C# and Dictionary?
Any ideas? need to do this iteration as fast as possible. In C I could do some pointer magic to achieve this, but I am not familiar with C# dictionary iterators/enumerators so I have no idea whatsoever how to solve this.
|
|
|
|
|
If you have huge arrays where there are large amounts of "missing" information you'd be better off using a linked list.
|
|
|
|
|
Maybe have one collection (HashSet?) to hold the indices? Only remove an index from the collection if both arrays have 0 at that index.
|
|
|
|
|
A Dictionary is not sorted, so you cannot do that.
Go through dict1 and compare/find the difference with the respective value in dict2 (or with 0, if that value does not exist).
Then go though dict2 and test for each value if it is contained in dict1. If it is, we already compared it in the step above; otherwise compare 0 to the value.
|
|
|
|
|
Ah crap...then I need to create a linked list manually I guess...
|
|
|
|
|
Any suggestions for how I can implement this using the built-int list or linkedlist?
Let us assume I have a stream of incoming pairs of keys (integers). If no such key exists in the list it should be added to the list (sorted by the key value) with the value 1 (1 occurrence). If the key already exists the previous entry should be increased by 1.
Now, lets assume I have two such lists. Now I need to compare these lists as fast as possible: for each key in the lists the value at this key should be compared with the value for the same key in the other list. If the key only exists in one of the lists then it is assumed that the value in that list was 0. if the key did exist.
Any suggestions? I have no idea how to use the built-in collection types for such advanced operations...especially when performance is of importance.
|
|
|
|
|
Hey all, I might have a somewhat newbie question as I haven't been using C# for too long yet.
Here it goes:
1) I have a listbox called lst_elements where i read data into from a MySQL DB table hs_a
2) I add items useing the sqlreader function in a while loop until there is no more data to be found.
read items in lst_elements would look like this in string
sqlReader.GetString("column_id")+ "\t" +sqlReader.GetString("column_name")+ "\n";
So i have a tab between first and second item(string) returned and a new line at the end of that row read.
Till here everything works fine. No problems at all
Now the tricky part, when I have an Item selected which was returned from my search I would like to query the server again but this time read out of
hs_a (unique index ID) then handle that ID which was returned for the selected item and read out of
hs_b from the returned ID another column which contains data for that specific ID. So to say table.hs_b contains the same uniqe IDs that hs_a has. I did this to relax the server abit more and hs_b contains data that is not always needed.
I am pretty familiar with the SQL Statements etc also the part on how to use it in C#.
If someone could help me out here I'd appreciate it, I might come up with a solution myself. Playing around with the code atm.
|
|
|
|
|
I do not see what your question is. Anyways, it is not a good idea to show column_id to user unless it is something meaningful, for example SIN. Look into DisplayMember, ValueMember properties of listbox and it should solve your problem. You can do what you want in a single query from db instead of querying again once an item is selected.
You have specified what you are doing but not what you would like to do so it is hard to make a suggestion.
Let me know if this is not what you are after.
|
|
|
|
|
I have a weird focus problem with a usercontrol I use for drawing. I have an mdi form with two child forms. Each form has a toolstrip and a usercontrol in it. The problem is, when I activate/enter/focus the form, it scrolls to top left of usercontrol. I didn't do anything such functionality and I can't understand why it does such a thing.
Here's a screenshot of my problem[^]
Any ideas what could cause this?
|
|
|
|
|
Paste some code then I can try to tell you the problem.
|
|
|
|
|
Thanks CodingYoshi. Here's the code I could think of maybe relevant to this. I don't know what else to paste.
Main parent form and how it opens mdi child form:
this.mdiChildForm = new MdiChildForm();<br />
mdiChildForm.MdiParent = this;<br />
mdiChildForm.Size = CalculateAvailableClientSize();<br />
mdiChildForm.Show();<br />
mdiChildForm.Start(i.Size);<br />
mdiChildForm.Location = new Point(0, 0);
Load event of mdi form which has usercontrol in it:
private void MDIChildForm_Load(object sender, EventArgs e)<br />
{<br />
this.userControl = new UserControl();<br />
userControl.Location = new Point(0, this.toolStrip.Height);<br />
<br />
this.Controls.Add(this.userControl);<br />
}
Start function
<br />
internal void Start(Size size)<br />
{<br />
this.userControl.Size = new Size(size.Width / Settings.Ratio, size.Height / Settings.Ratio);<br />
this.userControl.DrawBackgroundImage(this.imageFile);<br />
this.toolStrip.Focus();
}<br />
There're no more events in both parent form and mdi form. UserControl has mouse down/up/move and paint events but they only has drawing functions like Graphics.DrawImage and Graphics.DrawRectangle and such. Also this problem is happening even when I don't click on the usercontrol but on the toolbar, form titlebar etc..
I'm completely confused over this
|
|
|
|
|
I don't know what the variable i is for (mdiChildForm.Start(i.Size)). Anyhow, debug and see what size you get for the user control when you set the size.
|
|
|
|
|
i is an Image object. I get the height and width of an image and set the size of the window according to that.
|
|
|
|
|
What scrolls to the top left corner? The form? The user control? The mouse pointer?
But fortunately we have the nanny-state politicians who can step in to protect us poor stupid consumers, most of whom would not know a JVM from a frozen chicken. Bruce Pierson Because programming is an art, not a science. Marc Clifton
|
|
|
|