|
Select Count(*) has to do the fuzzy like search on the whole table just to show rows that match might exist - so it will probably do a full table scan (if start of like is a %)
better is to let SQL return as soon as it has found one row that matches - so use exists - e.g.
String.Format("SELECT 1 WHERE EXISTS (SELECT 1 FROM data WHERE oznacenie LIKE '{0}')", data)
That way SQL can stop looking after the first row it finds that matches. Depending on size of table this can make a huge difference in performance. This will return 0 or 1 records to the rowcount which you can get using ExecuteScalar return
|
|
|
|
|
Love that...
|
|
|
|
|
var cn = New System.Data.SqlServerCe.SqlCeConnection("Data Source=" + values.DatabaseFile);
cn.Open();
var cmd = New System.Data.SqlServerCe.SqlCeCommand("SELECT Count(ID_COL) FROM data where oznacenie like '" + data + "'", cn);
var count = cmd.ExecuteScalar();
this seems to be an optimized solution to me, shouldn't use '*' if we can do without it cause you don't know what kind of nutter designed the database. I have seen tables with 45 columns that slows down the query. Always prefer to specify exact columns I need in the queries.
|
|
|
|
|
if (currentRadioButton.Checked == false) return;
{
ViewManager.ShowOutputForm(this.ParentForm.MdiParent, eOutputForm);
InitRiskReturnToolWindow(m_eMode);
}
Doesn't actually cause an error, but the GALL of someone to leave that in MY codebase....
|
|
|
|
|
My eyes slipped right by the "return" at first. That's just... unnatural.
|
|
|
|
|
I know. Look forward to more of these from me over the next few months as I wrest this codebase into something resembling a proper application....
|
|
|
|
|
Wow! That's something really new here!
A very nice way to obfuscate code.
|
|
|
|
|
I'm always in search for obfuscate code.
|
|
|
|
|
I read it once and was like 'Huh, what's the problem?'. And then I saw it. That's the sign of a true horror.
I don't think this even gives a warning in C# because the if is fully formed and bracing for scope is fine.
|
|
|
|
|
BobJanova wrote: That's the sign of a true horrorprankster. FTFY
Oxfords English < Official CCC Players Dictionary
Excuse me for my improper grammar and typos.
It's because English is my primary language, not my first language.
My first languages are C# and Java.
VB, ASP, JS, PHP and SQL are my second language.
Indonesian came as my third language.
My fourth language? I'm still creating it, I'll let you know when it's done!
|
|
|
|
|
This is one of the reasons why I always brace single line if statements - it is too easy to miss what is happening especially if someone or something (code prettifiers etc) mangle the code like you have found.
|
|
|
|
|
That is a work of art!
|
|
|
|
|
Names changed to protect the innocent....
private void FillGrid()
{
}
private void Case_SelectionChanged(object sender, EventArgs e)
{
FillGrid();
}
private void FillCase(string PatientID)
{
case.ItemIndex = 0;
}
protected void Search()
{
FillCase(PatientID);
case.EditValue = caseNo.Trim();
Case_SelectionChanged(new object(), new EventArgs());
FillGrid();
}
So, in 4 lines of code in Search(), we call a lengthy FillGrid function 4 times....Really?
modified 25-Oct-11 12:06pm.
|
|
|
|
|
That example is not complete, is it? All of the functions you show are private/protected, none is public, and only one gets called by a user interaction. The real fun must be somewhere else. Didn't you see a function like:
private void Button1_Click(object sender, EventArgs e)
{
FillCase("");
Search();
Case_SelectionChanged(new object(), new EventArgs());
FillGrid();
FillCase("some value");
Search();
Case_SelectionChanged(new object(), new EventArgs());
FillGrid();
... and some more lines of code
}
|
|
|
|
|
He just wanted to be on the safe side and assured that the grid is filled, no matter what happens
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
From what I can see the grid won't actually be filled if the FillGrid throws an Exception. Unless there is a deleted try catch block there that recursively calls the FillGrid Method again in its catch block...
It's an OO world.
public class Naerling : Lazy<Person>{}
|
|
|
|
|
Did you got the guy fired, cause of such guys the software can't cope up even with hardware advancements. Even with a quad core machines and GBs of RAM we still have the same performance issues we used to have in the days of Pentium I and a few MB of RAM.
|
|
|
|
|
AsOfDateBlankLabels();
if (this.g_eFormMode != PortfolioDetailFormMode.Portfolio_Edit)
{
c_boolSetDefaultValues = false;
}
c_boolSetDefaultValues = true;
I need say no more.
And before you ask, AsOfDateBlankLabels doesn't use it. At all.
|
|
|
|
|
Where's the problem ? It compiles... :p
/me running
|
|
|
|
|
Did I read it wrong but it looks the the "c_" variable will always be true
|
|
|
|
|
Exactly ; there's no point here to set it to false in the if statement as it is assigned to true just right after.
|
|
|
|
|
Sorry... it is in there for Justin Case
(yes|no|maybe)*
|
|
|
|
|
That's what you get when you pay coders by the line.
Heck, sometimes they'll even throw in documentation!
|
|
|
|
|
Bert Mitton wrote: documentation
What?
|
|
|
|
|
public FileContentResult ExportToExcel(object datasource)
{
var grid = new GridView();
grid.DataSource = datasource;
grid.DataBind();
var sw = new StringWriter();
var htw = new HtmlTextWriter(sw);
grid.RenderControl(htw);
byte[] excelFileBytesContent = this.Response.ContentEncoding.GetBytes(sw.ToString());
var excelFileContentResult = new FileContentResult(excelFileBytesContent, "application/vnd.ms-excel");
return excelFileContentResult;
}
It kinda works, but WTF???
|
|
|
|