Friday, September 28, 2012

IList vs List

I will give very simple example

 Lets say we have a class library and we have class1 as class
 It has 2 methods
public IList getList()
{
 IList mylist=new List();
mylist.add("hello");
 mylist.add("hi"); return mylist;
 }

public List getList()
{
List mylist=new List();
mylist.add("hello");
mylist.add("hi");
return mylist;
 }

Now when the class library is being used. and it happens than you need to change the Collection from List to Array or indexed type.

We can do this.......
public IList getList()
{
IList mylist=new int[10];
 lst[0] = 10; return mylist;
 }
But We cannot do this.....
public List getList()
 {
 List mylist=new int[10];
lst[0] = 10; return mylist;
 }

Friday, April 29, 2011

This was a challenge given to me by my colleague few days ago He told me there are some rows in a table which are identical Not a single field change. but I want to delete all the other rows.. and Keep Only one intact This is what i did


declare @var as int
select @var=(cast(count(empid) as int)) from city where city='bengal' and empid=3
delete top(@var-1)city from city where city='bengal' and empid=3


--here city is table name and there are 2 columns empid and city. --In sql server 2005 and above you can do by following way

Tuesday, April 26, 2011

Smart Grid for India

With Smart Grid taking center stage on most media platform including YouTube, SmartGridIndia has selected 10 most interesting Smart Grid videos from Youtube that are worth watching. Check out this 10 videos!



1) Smart Grid Intelligent Energy use - One of the earliest video about Smart Grid introduction







2) How Smart Grid will power electric cars by Siemens







3) A completed Smart Grid demonstration video by KEPCO











4) How Smart Grid improves reliability through Virtual Power Plant by EPRI









5) The working of Smart Grid and its benefits







 6) The complete understanding of Smart Grid by GE







7) Smart Grid informative video by Cisco







8) Microgrid and the role of storage by AltairNano







9) Smart Grid Pilot video by AEP







10) Working of Smart Grid - Simple way



Wednesday, February 23, 2011

Csharp Code : A Better Way To Encrypt And Decrypt String

There Are Many Scenarios in .Net C# where You will need this encryption and description
Include the following namespaces(Apart from other mandatory)

using System.Security.Cryptography;
using System.Text;
---------------------------------------------------------------------------------------
public static String encryptor(String originalPassword,string strkey)
{
TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
DES.Key = md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strkey));
DES.Mode = CipherMode.ECB;
Byte[] byteData = ASCIIEncoding.ASCII.GetBytes(originalPassword);
return Convert.ToBase64String(DES.CreateEncryptor().TransformFinalBlock(byteData, 0,
byteData.Length));
}

public static String Decryptor(String DrcPassword, string strkey)
{
TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
DES.Key = md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strkey));
DES.Mode = CipherMode.ECB;
Byte[] byteData = Convert.FromBase64String(DrcPassword);
return
ASCIIEncoding.ASCII.GetString(DES.CreateDecryptor().TransformFinalBlock(byteData, 0,
byteData.Length));
}
------------------------------------------------------------------------------------------
You can invoke these methods by

String strGetEncrypted=encryptor("mySecretThing","myMasterkey");
String strGetDecrypted=decryptor("strGetEncrypted","myMasterkey");

This is it..Keep On Automating things.
--------------------------------------

Wednesday, May 5, 2010


Nature's Play Station

Built a torch with nuclear fusion
dazzles, with its light and shine
The savior, we call it the SUN

Spinned a ball in slow motion
has most of resources in dearth
The mother, we call it the Earth

Designed a natural blowing fan
the extreme speed ,no one to contend
The speedster, we call it the Wind

Created a sprinkler with mineral water
Sprays uniformly on both sea and terrain
The curator,we call it the Rain

Produced a versatile magic stick
fulfills every want
The sacrifier, we call it Plant

On this playground with spotlight
gave rise to innocent,sensitive feebles
The unfortunates,we call them the Animals

Finally gave birth to a creature
with selfish,cruel and cunning brain
The destroyer,we call them the Human??

The Human betraying his builder
performing nuclear fission
will suicide with his mission.

Written By :Mahendra Apte

Sunday, April 18, 2010

Thinking Of You

Just you are in my mind,
And you are my miss world..

Please clarify my confusion,
In a, rush of people
Only you are visible
Is this a reality or illusion..

In the season of sunny skies
want to be a nightingale
and tweet you for mingle
under the shade of cloudy skies..

your presence,make my heart play
like, the strings of guitar
plucked by a rockstar
making me , fly high in sky..

you always present in my dreams
oh god make me a nightbird
open my dream doors
let me realize the romance..

You are, the beautiful person
shocked, on your first glance
there is only one desire,
that you be my life companion..

May be i am a hummingbird
but,gifted with wings of archangel
can fly towards the heaven
to persuade god to make you smile..


when you walk back
gives me immense pain
either, tell me god how to sustain
or give me , the time back..


Just you are in my mind,
and you are my miss world..

Written By : Mahendra Apte

Saturday, April 17, 2010

change connection string in app.config programmatically/Runtime

Step 1 : Create a New  windows Forms application named configwrite

Step2 :  On Form put a button and a label

Step 3 : In code behind on click event of the button write the code
            shown below

 private void button1_Click(object sender, EventArgs e)
        {
Configuration c =        System.Configuration.ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
      c.ConnectionStrings.ConnectionStrings["connectionstring"].ConnectionString = "SERVER=changedservername; DATABASE=database; uid=username; pwd=password;";
            c.Save();
            label1.Text = "Connection String Changed";
      }

Note : The change in connectionstring is reflected in the
          configwrite\bin\debug\configwrite.exe.config  File

Sending SMS from asp.net through way2sms...

C#.net:




Step 1: Add Web Reference : 
        http://www.spiritssoft.com/webservice/sendway2sms.asmx


           //if your classname is classname1 and servicereference is ServiceReference1


Step 2: Add This "using classname1.ServiceReference1;"


Step 3:

            SendWay2SmsSoapClient client = new SendWay2SmsSoapClient();
            string strResult = client.sendSmsSpiritsSoft("username", "password",                   "number to send","message");

Thursday, April 15, 2010

Clear event logs


This is needed when your defined log file size for database is limited..Badly needed during
debugging stored procedures.


Clear Sql log files >>>


Step 1 : open visual studio >> open view menu >> your server name>>Event Logs --->rt click>>launch eventviewer
Step 2 : Event Viewer window opens
Step 3 : Event viewer(local) >>application --->rt click >> Clear All Events :)

Sunday, April 11, 2010

Swap bit values of a column using update query

Suppose there is a situation in which
There is column named pass/fail.which has default values 1/0
Respectively.
Now by mistake you have inserted it as 0 for pass and 1 for fail.
Now you need to update but you cannot do it easily because,

If i write query like this "update result set pass=1 where pass=0"
or update result set fail=0 where fail=1
this will surely create a havoc.
So, we need to toggle both bit values at a time
For which you can write it as
update result set pass=pass ^1 
this is called XOR operation


This will do the task happy Querying...:-)