I was developing C#/SQL code generator and i was struggling little bit how to add double quote (") in C# .. and this is how
string selectCommand = string.Format("command.CommandText = \"SELECT * FROM [{0}]\";", entity.TableName));
Tuesday, December 16, 2008
Wednesday, August 13, 2008
Descending sortedList by value
sorted lists are normally sorted by key not value in ascending order. this is how to create a sorted list by value in descending order
class DescendingComparer : IComparer
{
public int Compare(object x, object y)
{
try
{
return System.Convert.ToInt32(x).CompareTo(System.Convert.ToInt32(y)) * -1;
}
catch (Exception ex)
{
return x.ToString().CompareTo(y.ToString());
}
}
}
class KeySortedList : SortedList
{
public SortedList ReversedList = new SortedList(new DescendingComparer());
public new void Add(object key, object value)
{
ReversedList.Add(value, key);
base.Add(key, value);
}
}
class DescendingComparer : IComparer
{
public int Compare(object x, object y)
{
try
{
return System.Convert.ToInt32(x).CompareTo(System.Convert.ToInt32(y)) * -1;
}
catch (Exception ex)
{
return x.ToString().CompareTo(y.ToString());
}
}
}
class KeySortedList : SortedList
{
public SortedList ReversedList = new SortedList(new DescendingComparer());
public new void Add(object key, object value)
{
ReversedList.Add(value, key);
base.Add(key, value);
}
}
Thursday, August 07, 2008
Undefined function 'CONVERT' in expression issue in Office 12
you might get a "Undefined function 'CONVERT' in expression" in Crystal Reports if you are using Office 12 Access DB, to correct this you have to convert the left hand function,
eg,
Undefined function 'CONVERT' in expression "Crystal Reports"
CDATE({ERYTHROCYTE_SEDIMENTATION_RATE_HEADER.COLLECT_DATE}) >= cdate (2008, 07, 05)
to fix the problem, good luck
eg,
Undefined function 'CONVERT' in expression "Crystal Reports"
CDATE({ERYTHROCYTE_SEDIMENTATION_RATE_HEADER.COLLECT_DATE}) >= cdate (2008, 07, 05)
to fix the problem, good luck
Monday, August 04, 2008
snapshot C# using PaintEventArgs
In RichFocus we had a problem to get the control image. We used old print screen methods to do this before, and it captures the whole thing with the windows on top of the control ... so I decided to use the OnPaint method to re-draw it for us.
// Inside snapshot control ...
Rectangle rect = this.ClientRectangle;
//create an empty image with the same size of the control
Bitmap bmp = new Bitmap(rect.Width, rect.Height);
Graphics g = Graphics.FromImage(bmp);
PaintEventArgs p= new PaintEventArgs(g, rect);
// paint the background,
this.InvokePaintBackground(this, p);
// this will invoke the control paint method
this.InvokePaint(this, p);
// Inside snapshot control ...
Rectangle rect = this.ClientRectangle;
//create an empty image with the same size of the control
Bitmap bmp = new Bitmap(rect.Width, rect.Height);
Graphics g = Graphics.FromImage(bmp);
PaintEventArgs p= new PaintEventArgs(g, rect);
// paint the background,
this.InvokePaintBackground(this, p);
// this will invoke the control paint method
this.InvokePaint(this, p);
Thursday, July 24, 2008
Sends the mail message asynchronously
public static void SendMailMessageAsync()
{
ThreadStart threadStart = delegate { SendMailMessage(); };
Thread thread = new Thread(threadStart);
thread.Start();
}
{
ThreadStart threadStart = delegate { SendMailMessage(); };
Thread thread = new Thread(threadStart);
thread.Start();
}
Wednesday, July 23, 2008
?? operator in C#
I found this C# today it's rock !!
string thisIsANull = null;
string thisIsANullCheck = thisIsANull ?? "";
thisIsANullCheck is set to ""
string thisIsANull = null;
string thisIsANullCheck = thisIsANull ?? "";
thisIsANullCheck is set to ""
Friday, February 15, 2008
descending sorting in SortedList
by default when you add an element to SortedList it's added in ascending order, for descending for you have to use a small trick.
internal class DescendingComparer : IComparer
{
public int Compare(object x, object y)
{
try
{
return System.Convert.ToInt32(x).CompareTo(System.Convert.ToInt32(y)) * -1;
}
catch (Exception ex)
{
return x.ToString().CompareTo(y.ToString());
}
}
}
SortedList membersList = new SortedList(new DescendingComparer());
membersList.Add()
internal class DescendingComparer : IComparer
{
public int Compare(object x, object y)
{
try
{
return System.Convert.ToInt32(x).CompareTo(System.Convert.ToInt32(y)) * -1;
}
catch (Exception ex)
{
return x.ToString().CompareTo(y.ToString());
}
}
}
SortedList membersList = new SortedList(new DescendingComparer());
membersList.Add()
Monday, January 21, 2008
Subscribe to:
Posts (Atom)