by Yugolancer
Posted on March 06, 2016
I see people bother with checking against NULL, using Coalesce, Substring etc. etc.
The solution is pretty simple actually. You just need to replace the two empty space by one if the middle name is null or empty e.g.
C#
FullName = (reader["FirstName"].ToString() + " " + reader["MiddleName"].ToString() + " " + reader["LastName"].ToString()).Replace(" ", " ");
T-SQL
REPLACE(FirstName + ' ' + MiddleName + ' ' + LastName + ' ' + Suffix, ' ', ' ') AS FullName
Read More
by Yugolancer
Posted on October 31, 2016
If you get this error it means that the default values are missing from your database.
To resolve/fix the issue, just execute the following SQL code against your database:
INSERT INTO
dbo.aspnet_SchemaVersions
VALUES
('common', 1, 1),
('health monitoring', 1, 1),
('membership', 1, 1),
('personalization', 1, 1),
('profile', 1, 1),
('role manager', 1, 1);
GO
Read More
by Yugolancer
Posted on February 04, 2016
If you get the following error you are about to get the solution either :)
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
Cause:
Usually it happens when you directly call say an Eval() function in the code-behind.
For example, you may have a GridView control with a label inside of the Template column:
<asp: id=" lblDescription " runat=" server " text="< %# Eval('Description') % >"></asp:>
Then for some reason you decide to move that to the code-behind AS IS so you say:
Dim lblDescription As Label = CType(e.Item.FindControl("lblDescription"), Label)
lblDescription.Text = Eval("Description").ToString()
Your project will compile but as soon as you try to open the certain Page, an exception ‘System.InvalidOperationException’ will be thrown.
Solution:
Just replace Eval() with DataBinder.Eval() making your code to looks like this:
Dim lblDescription As Label = CType(e.Item.FindControl("lblDescription"), Label)
lblDescription.Text = DataBinder.Eval(dataItem.DataItem, "Description").ToString()
Voila! Your problem has been solved.
Read More
by
Posted on June 03, 2017
Say that you have a comma-separated String containing user IDs like following:
String userIDs = "1,2,5,8,23,67,101";
and that you want to fetch those users without splitting and looping their IDs.
Usually you do use CharIndex to search the expression:
command.CommandText =
"SELECT * FROM Users WHERE CharIndex(CAST(userID AS varchar(8)) + ',', + @userIDs) > 0";
command.Parameters.AddWithValue"@userIDs", userIDs;
However if you execute the above query the last ID will be omitted YEAH it will be indeed because it checks against value + comma which does not match when it comes to 101.
FIX: add the missing comma to the end of the string:
command.Parameters.AddWithValue"@userIDs", userIDs + ",";
Hope this helps someone!
Read More
by
Posted on September 17, 2017
SELECT
NameEN
FROM
Country
ORDER BY
CASE WHEN NameEN = 'Switzerland' THEN 0 ELSE 1 END, NameEN
Read More
by
Posted on February 22, 2018
As mentioned many times by now, Debugging is a discipline that requires patience, and a fervent attention to detail.
When it comes to solving difficult problems, issues or bugs, you need to locate, and resolve the problem's root cause.
Usually it happens that, after going through one idea after another and hitting debug button for an hour (usually more like 2 or 3 hours), you are not closer to solving the problem than you were when you started.
Now, all you've done is wasted a few hours of time, and worked yourself into a desperate and frustrated state that is not conducive to thinking rationally, and applying logic.
Simply because you don't actually have any clue what's causing the problem you are just shooting blindly.
The problem is often, if not always, more complicated than we would like.
As developers, we would much rather add new features, or write the next great algorithm, than try to figure out why something we wrote a month ago is suddenly no longer working.
"Stop thinking, and look!" - is one of the maxims from David Agan who points out that the engineers like to think and not to look.
Why? Well because the thinking is fun. In fact, for a lot of us it's probably why we became software engineers in the first place.
So why do we insist on being able to locate a bug by thinking about it? Probably because it's a lot easier than looking for it.
Of course, looking is tedious. Sometimes you don't even know where to start looking.
However, in order to be certain that you're fixing the right problems, and that you can prove that you've fixed it, make sure that every time you debug a problem you:
- Observe the issue in action
- Apply your fix
- Observe that the issue is resolved
If you don’t do these steps, in that order you can’t know if you actually solved the issue at hand, another different issue, or just wrote a bunch of code that does nothing at all.
So avoid frustration, don't waste time solving the wrong things, and stop thinking, and look already!
Read More
by
Posted on April 05, 2018
CREATE TRIGGER [dbo].[ESR_INSERT]
ON [dbo].[Loan] FOR INSERT AS
UPDATE
Loan
SET
ESR = '01' + ' ' + FORMAT(Loan.Id, '00000') + '...'
FROM
Loan
JOIN
Inserted
ON
Inserted.Id = Loan.Id
WHERE
Loan.ESR IS NULL
Read More