|
Eddy Vluggen wrote: A "null" value in a database is not the same an empty string You haven't ever worked with an Oracle DB, have you? 
|
|
|
|
|
Aw, I did, but it has been a while since Oracle 7 and selecting from 'dual'
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I believe this works in Oracle too?
If issues, please explain, you made me curious...
|
|
|
|
|
Well, look at it from a different perspective. Imagine a questionnaire. Someone left a free-text field empty. Does that translate to a null value or string.Empty ? Hence an empty string and a null string are the same in an Oracle database. If there's a "not null" constraint on the text field, you cannot insert an empty string either.
At first, I thought that's a WTF. But now I think they got it right.
|
|
|
|
|
As Eddy Vluggen mentioned:
if(dataMySqlReader["user"] != DBNull.Value){
}
else{
}
hope this helps.
modified 1-Jun-16 7:32am.
|
|
|
|
|
Won't that produce an InvalidCastException if the field is null?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Oops, my copy/paste error ...
I'll fix that...
|
|
|
|
|
Thanks but it does not work
|
|
|
|
|
What does "not work" mean exactly?
Did it throw an error? If yes, what was the message?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
my variable can not affected
|
|
|
|
|
Show us some updated code, maybe we could talk about it
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
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...
|
|
|
|
|