|
hey,
I wrote some Console application (implementation of KNN Algorithm).
It's involve Polymorphism (for different distance calculation), in console everything works great, but the problems began when i tried to add UI to it.
i added a new project (WinForm) and setted it to be a startup Project, then as usual i referenced a console (which become a logic layer) and after i do a rebuild for the whole solution i get an "Error 4 Metadata file ..." compilation error...
I checked in the debug folder of console application, and the ".exe" file was missing.
what is the problem here ?
thanks in advance
|
|
|
|
|
I'm not sure what you are doing, so I'll say this instead...
I have some utilities that run as console applications when executed with command-line parameters and as WinForms applications when run without command-line parameters. Is that what you are trying to do?
To achieve this:
0) Set the project to be a console application
1) In the Main method, detect which mode you want, if you want to launch the form:
1.1) Call the Windows API method FreeConsole (to close the console window)
1.2) Run your form as you normally do
<pre lang="text">
if ( args.Length == 0 )
{
PIEBALD.Lib.LibApi.FreeConsole() ;
PIEBALD.Types.Singularity.ThereCanBeOnlyOne ( typeof(frmDBTW) ) ;
}
else
{
... Console mode code ..
}
</pre>
|
|
|
|
|
Hey guys, I have a problem, I run a code in sqlQuesry builder and it works just fine but when I apply the same thing in C# code it doesn't work !!!
in SQLQuery Builder
SELECT ID, StuName,
StuLName, Shenasnameh, StuLandline, StuMobilePhone,
StuEmail, StuAddress
FROM Students WHERE StuName like N'کیوان%'
the above code works perfectly and I get the result I want but the below code doesn't
SELECT ID, StuName,
StuLName, Shenasnameh, StuLandline, StuMobilePhone,
StuEmail, StuAddress StuEmail, StuAddress FROM Students WHERE StuLName
like N'" + StuLName_tb.Text + "%'";
I'm puzzled here because It the same code, am I missing something ???
|
|
|
|
|
I think that you have too many quotes in there. Try altering
like N'" + StuLName_tb.Text + "%'";
to
like N"'" + StuLName_tb.Text + "%" + "'";
What I think you are getting now is literally + StuLName_tb.Text%'
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Henry Minute wrote: I think that you have too many quotes in there
so you suggest to add three double quotes?
in fact, I don't see anything wrong in the original query; I suspect there is a regional setting or an encoding problem somewhere.
|
|
|
|
|
Judging by the way that the code was formatted within the pre tags, StuLName_tb.Text was part of the string and not the value of the property.
This may simply be the result of the way that CP formatting/parsing differs from the way that VS does it.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I do hope you will feel better tomorrow.
|
|
|
|
|
Thank you for your kind thoughts.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
You're welcome. Have a good night!
|
|
|
|
|
You're opening yourself up to SQL injection attacks[^] by doing stuff like this. You may want to consider using a SqlCommand .
/ravi
|
|
|
|
|
mrkeivan wrote: am I missing something ???
StuEmail, StuAddress<code>,</code> StuEmail, StuAddress FROM Students WHERE StuLName
--------------------^ A comma?
--edit
mrkeivan wrote: when I apply the same thing in C# code it doesn't work !!!
Does that mean that it doesn't return anything, or does that mean that it generates an error? If so, what error?
I are Troll
|
|
|
|
|
well spotted. I overlooked that, he has a comma/field imbalance, too many field names if you ask me.
|
|
|
|
|
Thanks
Would be too simple though; I guess he would have spotted that himself, probably due to copy/paste. I think you're right suspecting the collation of the field.
I are Troll
|
|
|
|
|
Luc Pattyn wrote: too many field names if you ask me
Yeah, those last two fields appear in there twice. Looks like a copy/paste error.
|
|
|
|
|
|
Is the wild card character (%) on the correct side of the search term in both cases? Maybe some problem with the right-to-left direction of arab.
Furthermore, how do you access your SQL server from C# - Ole, Odbc, the sql server classes...?
When you do the query without the WHERE statement, do you then get "correct" data or a collection of non-printable characters?
|
|
|
|
|
please don't remove messages, as you did here[^]. It is against the forum guidelines.
|
|
|
|
|
Hi all,
Can someone let me know what is happening with the following line of code? I don't understand the syntax used in after j == (arr[i].Length - 1)
Specifically what's happening with ? "" :
I do know what " " is doing at the very end.
System.Console.Write("{0}{1}", arr[i][j], j == (arr[i].Length - 1) ? "" : " ");
|
|
|
|
|
the ternary operator ?: is used to choose between an empty string and a space.
x?y:z is an expression that evaluates to y or to z, depending on the boolean value of x.
another example would be:
bool equals = a==b;
Console.WriteLine(equals ? "a==b" : "a!=b");
|
|
|
|
|
? is the ternary if operator. if the condition ( j == (arr[i].Length - 1) is true, it outputs"" (the null string), if the condition is false, it outputs " " (one space.
|
|
|
|
|
Just in case you didn't understand the answers in the previous two replies.
System.Console.Write("{0}{1}", arr[i][j], j == (arr[i].Length - 1) ? "" : " ");
is the same as
string result = string.Empty;
if (j == (arr[i].Length - 1))
{
result = "";
}
else
{
result = " ";
}
System.Console.Write("{0}{1}", arr[i][j], result);
The ternary operator ?: is a shorthand version of if - else. See here[^].
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
What happens with the sequence points though? For the ternary operator there is a sequence point between the condition and the second/third operand (whichever it chooses), but AFAIK not after the second/third operand (unless you close it with a semicolon, of course)
Or did MS sneakily add some sequence points there, like they did with method arguments?
|
|
|
|
|
It is beyond my capabilities to give a definitive answer to that although I suspect that Luc might be able to.
As a guess though, and knowing how sneaky M$ are, I'd go for the latter.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Disclaimer: I don't know the finer details as I don't really care; with 20+ years of C under the belt (using all kinds of compilers) I have learned to stay well away from the borders. Defensive programming is what I call it. Besides, doing so improves readability and robustness of the code.
But then I decided to browse the C# 3.0 spec anyway, and here are some findings:
1.
the notion of "sequence point" does not appear in the C# standard.
2.
"The order of evaluation of operators in an expression is determined by the precedence and associativity of the operators (§7.2.1)."
3.
"If the array creation expression contains an array initializer, then each expression in the array initializer is evaluated and assigned to its corresponding array element. The evaluations and assignments are performed in the order the expressions are written in the array initializer"
4.
"A method decorated with the Conditional attribute is a conditional method. The Conditional attribute indicates a condition by testing a conditional compilation symbol. Calls to a conditional method are either included or omitted depending on whether this symbol is defined at the point of the call. If the symbol is defined, the call is included; otherwise, the call (including evaluation of the parameters of the call) is omitted."
I did not find:
- a single thing about side-effects
- evaluation order of method call arguments
which does not mean it isn't covered, there are over 500 pages in the spec.
Note: as 4.0 supports named arguments (and hence accepts them in any order), the problem potentially gets larger.
|
|
|
|
|
I don't think there can be any side effects in C#, because objects (and everything is an object), are essentially static in nature. For example in C, an operation like x++?: could introduce some ambiguity, while in C#, x and x++ are distinct objects.
Am I out of my depth here? Absolutely
|
|
|
|