Friday, March 09, 2012
#
So, this morning, my phone was locked out after many wrong lock pattern entries.
Phone was asking for gmail username/pass. For some reason, it was not accepting the correct username/password.
It was relief when it occurred to me that I had two step verification enabled.
I disabled the two step verification from my PC and was able to log into the phone :)
Monday, December 12, 2011
#
Here is a extension method which can be used to perform the Delete operation on a DataTable just like the select i.e. using a filterExpression:
using
System;
using
System.Collections.Generic;
using
System.Data;
using
System.Data.SqlClient;
public
static
class
MyExtensions
{
///
<summary>
///
Delete row based on filterExpression
///
</summary>
///
<param name="dt"></param>
///
<param name="filterExpression">
just like select
</param>
///
<returns>
number of deleted rows
</returns>
public
static
int
Delete(
this
DataTable
dt,
string
filterExpression)
{
int
nor=0;
// number of rows deleted
DataRow
[] toBeDeleted;
toBeDeleted = dt.Select(filterExpression);
if
(toBeDeleted.Length > 0)
{
foreach
(
DataRow
dr
in
toBeDeleted)
{
dt.Rows.Remove(dr);
nor++;
}
}
return
nor;
}
}
Friday, July 16, 2010
#
I ended up using the MS Excel objects to convert files from XLS to CSV . Converted CSV had comma "," as field separator. But, what if the a filed content has comma like "lastName,FirstName". Now if you use default .net split method to get the fileds of a row in csv file, it will treat "lastName,FirstName" as two fields. I ended up writing my own split method which will take care of the comma in fields:
Private Function CustomSplit(ByVal sText As String,ByVal sSeparator As String) As String()
Dim RetrunArray As New ArrayList
Dim CurrentIndex As Int32
Dim CommaIndex As Int32
Dim CurrentField As String
Dim NextChar As String
CommaIndex = sText.IndexOf(sSeparator)
While(CommaIndex>0 and CommaIndex<sText.Length)
CurrentField = sText.Substring(CurrentIndex,CommaIndex-CurrentIndex)
RetrunArray.Add(CurrentField)
NextChar = sText.Substring(CommaIndex+1,1)
If(NextChar.Equals ("""")) Then
CurrentIndex = CommaIndex +1
CommaIndex = sText.IndexOf("""",CommaIndex+2)
CommaIndex = CommaIndex +1
If(CommaIndex<sText.Length)
NextChar = sText.Substring(CommaIndex,1)
If(Not NextChar.Equals (",")) Then
CommaIndex = sText.IndexOf(",",CommaIndex+2)
End If
End If
Else
CurrentIndex = CommaIndex +1
CommaIndex = sText.IndexOf(sSeparator,CurrentIndex)
End If
End While
'Pick up last field
CurrentField = sText.Substring(CurrentIndex)
RetrunArray.Add(CurrentField)
Return RetrunArray.ToArray(Type.GetType("System.String"))
End Function
Presumption/limitation:
- yearly holidays are stored in a table
- maximum 2 consecutive holidays
Table structure: HOLIDAY_DATE (DATETIME),HOLIDAY_DESC (VARCHAR)
DB Script :
DECLARE @CurrentDay DATETIME
DECLARE @LastWorkingDay DATETIME, @CurrentWeekDay INT
SET @CurrentDay = CAST(CONVERT(VARCHAR, GETDATE(), 101) AS DATETIME)
SET @LastWorkingDay = CAST(CONVERT(VARCHAR, GETDATE(), 101) AS DATETIME)
DECLARE @DaysToLastWorkingDay INT
SET @DaysToLastWorkingDay = 0
SET @LastWorkingDay = DATEADD(day, -1, @LastWorkingDay )
--check if yesterday was holiday
IF EXISTS (SELECT HOLIDAY_DATE FROM tblHOLIDAY WHERE HOLIDAY_DATE =CAST(CONVERT(VARCHAR, @LastWorkingDay, 101) AS DATETIME))
BEGIN SET @LastWorkingDay= DATEADD(day,-1, @LastWorkingDay)
END
-- adjust for weekends, if needed
SET @CurrentWeekDay = DATEPART(weekday, @LastWorkingDay)
IF @CurrentWeekDay IN (1, 7)
SET @DaysToLastWorkingDay = (CASE @CurrentWeekDay
WHEN 1 THEN -2 -- 1 = Sunday
WHEN 7 THEN -1 -- 7 = Saturday
ELSE 0
END)
SET @LastWorkingDay = DATEADD(day,@DaysToLastWorkingDay, @LastWorkingDay)
IF EXISTS (SELECT HOLIDAY_DATE FROM tblHOLIDAY WHERE HOLIDAY_DATE =CAST(CONVERT(VARCHAR, @LastWorkingDay, 101) AS DATETIME))
BEGIN
SET @DaysToLastWorkingDay = -1
IF EXISTS (SELECT HOLIDAY_DATE FROM tblHOLIDAY WHERE HOLIDAY_DATE =CAST(CONVERT(VARCHAR, DATEADD(day, -1, @LastWorkingDay), 101) AS DATETIME))
SET @DaysToLastWorkingDay = @DaysToLastWorkingDay - 1
SET @LastWorkingDay= DATEADD(day,@DaysToLastWorkingDay, @LastWorkingDay)
END
SELECT @LastWorkingDay
Thursday, September 17, 2009
#
I got this error on production for a report which was working fine in Dev and it took me a while to figure out the cause.
Report's Data Source was pointing to a SQL Server View, when I looked at the SQL Query ( Database - > Show SQL Query ), I noticed that Database name was there with view name: "DbName.dbo.ViewName"
I did a lot of googling, trying to figure out a way to change this behaviour and have just "dbo.ViewName" in SQL, but in vain.
For now, I have fixed it by putting the SQL in the view within a Command in Crystal Report and its working.
Its kind of OK for this report as view had a small SQL and report is pretty small.
I would love to find REAL solution though, Crystal Reports does not always put the DBName with View.
Wednesday, August 19, 2009
#
Quite Straight forward:
- Select the Column , Right Click -> Propoerties OR hit F4
- Visibility -> Hidden -> Expression i.e. Click on Hidden under Visibility and select Expression from Drop Down
- Write the expression e,g.
=IIF(Parameters!MonthlyOrYearly.Value.Equals("Monthly"),false,true)
compared to FormatDateTime Good old 'Format' function makes the job a lot easier :
- Format(Fields!ResultDate.Value,"M/d/yyyy")
- Format(Fields!ResultDate.Value,"yyyy")
=IIF(Parameters!MonthlyOrYearly.Value.Equals(Monthly"),Format(Fields!ResultDate.Value,"M/d/yyyy"),Format(Fields!ResultDate.Value,"yyyy"))
Friday, August 07, 2009
#
I was trying to add a new field in an Oracle DB table using this script:
alter table TABLENAME add FIELDNAME char(1) not null default '0' ;
it was throwing an error:
'ORA-30649:missing directory keyword'
it drove me nutts for a while and after some googling, I was able to figure it out, its the Order: 'not null' should come after default value. right script is:
alter table TABLENAME add FIELDNAME char(1) default '0' not null;
order does matter :)
Wednesday, March 25, 2009
#
A JavaScript object can be of great help when you need to pass multiple values to a Modal Window. E.G.
var objArgs = new Object();
objArgs.Value1 = "Value 1";
objArgs.Value2 = 2;
var modalWindowFeatures = 'dialogHeight:600px;dialogWidth:600px;scroll:no;status:no;resizable:no';
url = 'relative/path/to/page';
var returnValue;
returnValue = window.showModalDialog(url,objArgs,modalWindowFeatures );
Wednesday, February 04, 2009
#
"Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression"
As the error message suggests , this normally occurs when you are assigning a T-SQL variable a value within sql query and the query is returning more that one rows e.g.
Declare @var1 nvarchar(50)
' select @var1=name from table1'
Putting 'top 1' can resolve the problem in many cases ( do check the business logic aspects):
' select top 1 @var1=name from table1'