Tuesday, March 15, 2011

Add Enum in Array List


System.Collections.ArrayList Al = new System.Collections.ArrayList();                      

Al.AddRange(Enum.GetNames(typeof(SqlDbType)));

PAN No Validation



I have validated a text box that only PAN NO should be enter in that text box
It should be of 10 character first 5 digit will be Alphabet next 4 digit will be number and next one is alphabet
here txtPAN(TextBox) length should be fixed 10 chracter
ex : BJJPA4563A

 private void txtPAN_KeyPress(object sender, KeyPressEventArgs e)
        {
            ValidatePANNO(e);
        }



   void ValidatePANNO(KeyPressEventArgs e)
        {
            if (!char.IsLetterOrDigit(e.KeyChar) && e.KeyChar != 8)
            {
                e.Handled = true;
                return;
            }

            if (e.KeyChar == 8)
            {
                return;
            }
            int len = txtPAN.TextLength;
            if (len < 5)
            {
                if (char.IsLetter(e.KeyChar))
                {

                }
                else
                {
                    e.Handled = true;
                }

            }
            else
            {
                if (len == 9)
                {
                    if (char.IsLetter(e.KeyChar))
                    {
                        return;
                    }
                }
                if (char.IsLetter(e.KeyChar))
                {
                    e.Handled = true;
                }
                else
                {
                    if (len == 9)
                    {
                        if (!char.IsLetter(e.KeyChar))
                        {
                            e.Handled = true;
                        }
                    }
                }
            }
        }

Saturday, March 12, 2011

How To delete Collection From Context in Entity Framework 4.0


To Delete All Object by using Entity Framework 4.0

To Delete All OrderDetails of Customer Object where OrderID=103

 var x = customerContext.OrderDetails.Where(c => c.OrderID == 103);
 customerContext.DeleteAll(x.ToList());
 customerContext.SaveChanges();

you have to defile DeleteAll method in a static class

namespace Application.Global
{

public static class GlobalMethods
    {
      public static void DeleteAll(this ObjectContext context, IEnumerable records)
       {
           foreach (T record in records)
           {
               context.DeleteObject(record);
           }
       }
    }

}



Wednesday, January 5, 2011

Restrict Special symbol in TextBox in C#

  private void ctlUL_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (!char.IsLetterOrDigit(e.KeyChar) && e.KeyChar!=8 )
                {
                    e.Handled = true;
                    return;
                }
         }

Monday, December 6, 2010

DateTimePicker Format in C#

Here are Some Different Types of Format of  DateTimePicker













dateTimePicker2.Format = System.Windows.Forms.DateTimePickerFormat.Short;

dateTimePicker3.Format = System.Windows.Forms.DateTimePickerFormat.Time;

dateTimePicker4.CustomFormat = "yyyy-mm-dd";

dateTimePicker4.Format = System.Windows.Forms.DateTimePickerFormat.Custom;

Saturday, December 4, 2010

Select Record between Months in SQL

select ID, Name, Month from (
    select ID, Name, Month,
        case Month
            when 'January' then 1
            when 'February' then 2
            when 'March' then 3
            when 'April' then 4
            when 'May' then 5
            when 'June' then 6
            when 'July' then 7
            when 'August' then 8
            when 'September' then 9
            when 'October' then 10
            when 'November' then 11
            when 'December' then 12
           
        end as MonthNo
    from
        Emp
 ) as TempTable
 where
    MonthNo between 1 and 12 order by [Month]

Wednesday, December 1, 2010

Convert String In Title Case C#


string s = "This is a test";
s = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s.ToLower())

Followers

Visitor No

click for free hit counter
Download a free hit counter here.