|
What's the error ?
Why doesn't it work?
|
|
|
|
|
But this version works !
it is very strange
string termUser = String.Empty;
termUser = "callow";
string catchTerm = String.Empty;
while (dataMySqlReader.Read())
{
catchTerm = (string)dataMySqlReader["user"];
if (catchTerm != null)
{
termUser = (string)dataMySqlReader["term"];
}
}
|
|
|
|
|
if dataMySqlReader["user"] is null this thing will crash I think...
Note that I updated my previous answer by removing the string cast (that was a copy/paste error)...
also this:
string termUser = String.Empty;
termUser = "callow";
is useless, use:
string termUser = "callow";
|
|
|
|
|
but
My variable [termUser] is affected by "callow" with this code :
it is very strange
string termUser = String.Empty;
termUser = "callow";
string catchTerm = String.Empty;
while (dataMySqlReader.Read())
{
catchTerm = (string)dataMySqlReader["user"];
if (catchTerm != null)
{
termUser = (string)dataMySqlReader["term"];
}
}
|
|
|
|
|
Just an observation:
Unless the SQL query returns exactly one record, the while loop will end up setting catchTerm to the "user" column from the last record returned, and termUser will be the "term" column from the last record where "user" isn't null (or empty).
Is there a reason that the "user" column can't be checked as part of the SQL query?
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
I think if the record does not exist, C # does not fit into the while loop
|
|
|
|
|
Yes, but if the SQL query returns more than one record, then the effects I mentioned will happen.
If the SQL query is structured to return only a single record (or none), then there's no issue.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
Suppose I have a hotel app where users can check to see if there is any vacant rooms in my hotel.
The vacancy status changes as old customers checkout and new ones checkin.
Does this situation require the Observer Design Pattern? Also if this is a WCF REST app, how do I simulate multiple people using this app?
modified 31-May-16 12:19pm.
|
|
|
|
|
It's not required; you could simply register checkins in a database.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi Eddy, thank you so much for sharing your thought on this.
What is the best way to stress test a WCF RESTful service to simulate multiple users accessing my app?
|
|
|
|
|
I dunno about the "best" way, but you could launch a lot of console-applications making requests
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Private Sub BACKToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BACKToolStripMenuItem.Click
Try
Dim t As New Form
For Each f As Form In Application.OpenForms
If f IsNot Me.ActiveMdiChild Then
t = f
Else
t.Activate()
Return
End If
Next
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message, "Error...!!!", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub FORWARDToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FORWARDToolStripMenuItem.Click
Try
Dim t As New Form
For i As Integer = Application.OpenForms.Count - 1 To 0 Step -1
Dim f As Form = Application.OpenForms(i)
If f IsNot Me.ActiveMdiChild Then
t = f
Else
t.Activate()
Return
End If
Next
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message, "Error...!!!", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
i converted this code to c#
private void BACKToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
{
try {
Form t = new Form();
foreach (Form f in Application.OpenForms) {
if (!object.ReferenceEquals(f, this.ActiveMdiChild)) {
t = f;
} else {
t.Activate();
return;
}
}
} catch (Exception ex) {
System.Windows.Forms.MessageBox.Show(ex.Message, "Error...!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void FORWARDToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
{
try {
Form t = new Form();
for (int i = Application.OpenForms.Count - 1; i >= 0; i += -1) {
Form f = Application.OpenForms(i);
if (!object.ReferenceEquals(f, this.ActiveMdiChild)) {
t = f;
} else {
t.Activate();
return;
}
}
} catch (Exception ex) {
System.Windows.Forms.MessageBox.Show(ex.Message, "Error...!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
can anyone tell me whats is the error in
Form f = Application.OpenForms(i);
backward is working forward is not working help me plz
|
|
|
|
|
VB uses round brackets '(' and ')' for both Method calls, and array accesses: C# doesn't.
round brackets indicate a method call:
Form f = Application.OpenForms(i); while square brackets '[' and ']' indicate an array:
Form f = Application.OpenForms[i];
Since Application.OpenForms is a Collection from the line above:
for (int i = Application.OpenForms.Count - 1; i >= 0; i += -1) {
You need to use square brackets, not round.
But...I'd do it with a foreach:
foreach (Form f in Application.OpenForms)
{
if (f != ActiveMdiChild)
{
...
Please, don't grab random chunks of VB and throw them through a code converter - they don't always get it right, and when they don't you need to think about them!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Well, first off, C# uses [] to index an array, not ().
So that line should be Form f = Application.OpenForms[i] .
Also, you need to give more information, like messages from the Error Window, to help us help you. The issue this time was obvious, but next time it may not be so.
If you want to do conversions between VB and C#, you may want to use an online convertor like the one from Telerik[^].
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
While I don't have the energy/stamina to really get deeply into understanding your code, let me point out a few things that may be helpful:
1. when you create a new Form named 't inside a method, a new instance of a Form is created ... however, the Application.ActiveForms property will not be incremented; it is only changed when you 'Show the Form, not when the new Form is loaded. The moment you exit the method, the variable 't ... of course ... is no longer valid (however, the Form it points to, is, of course, still there).
1.a. in the case of an MDI app, Application.OpenForms has a 'count of #1 when the MDI Form is opened.
1.b. when you 'Hide a Form that has been 'shown, it remains in the Application.OpenForms collection. and, of course, when you 'close it it is removed from that collection.
2. when you assign an existing Form to 't, you have then thrown away the reference to a Form in 't !
The key issue for planning the relatively simple task of handling "forward and back" is whether you will have multiple MDIChildForms open at once, or want to show them one-at-a-time. Another issue is whether you let the user close a given MDIChildForm, or instead 'Hide that Form so you can re-use it.
If you do allow the user to 'Close a child Form then: do you re-create it on demand ?
I suggest you post more information here about what you are trying to do, and answer the specific questions I've asked. I'll be happy to help with your code, when I know a little more about your goal.
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
Hi All,
I use visual Studio 2005 and build a web application and it is running at customer server from 2010.
My problem is when I try to run it from Code in visual studio 2005
the login page shown and when I click the login button the following error occurred.
" Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machinekey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster".
Please help me ASAP to solve this issue.
Thank You
|
|
|
|
|
Wrong forum. This has nothing to do with C#. You'll want to post this question in the ASP.NET[^] forum.
|
|
|
|
|
I have an windows Application , which has a grid in the inner most child window. But I fail to find the handle of the controls placed inside this child window. How can I scarpe such controls . Please help .
|
|
|
|
|
Show us what you tried - we have no idea how you organised stuff (or even exactly what you are trying to do!)
Code fragments help us understand: so give us the way you load the grid (and exactly what kind of grid it is), and the code you tried to "scrape" the controls.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
And, please include your explanation of exactly what "scrape" means in this context; we most often encounter the term "scrape" in the context of selecting content from a web-page.
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
If you got source code or are using reflection:
Child controls of Windows Forms windows can be accessed via the .Controls property (of the window).
"Content" of a WPF Window can be accessed via the .Content property.
|
|
|
|
|
If there's no handle, it might not be a control; it may be simply drawn by the application itself.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
What type of "windows application" do you have? Is it a .Net Windows Forms application, a WPF application, an old style C++ application, a Java application with Ant or Swing, ...?
Some of them do not use Windows controls for all purposes, sometimes they use them for underlying containers only (Swing, WPF), and then the inner "controls" do not have a handle.
|
|
|
|