Thursday, January 5, 2012

OrderBy and GroupBy in LINQ

If you are familiar with SQL,You would know it can enable you to perform some relational operations like the data to be returned in a specific Order and get the summary values based on the rows in each group.Here the LINQ is provide the same functionality
OrderBy:
The OrderBy is used to retrieve the data in particular order.The OrderBY expects a method as its argument.This methods identifies expressions that you want to use to sort the data.
For this i will show an example to get names of each city in AllCountry array
IEnumerable citynames=Allcountry.OrderBy(acoun=>acoun.CityName).Select(City=>city.CityName)
List li=New List();
 foreach(string name in Country)
  {
         li.add(name);
  }
 foreach (string s in list) // Loop through List with foreach
  {
 Console.WriteLine(s);
  }
The OrderByDescending is get the data in descending order.Here there one method i.e ThenByDescending which is used for more than one key value
GroupBy:
The GroupBy method is used to group the data to common values in one or more Fields.The GroupBy method expects a methods that specify the fields to group the data
var citiesGroupByCountry= Allcountry.GroupBy(acoun=>acoun.Country);
foreach(var citiesPerCountry in citiesGroupByCountry)
{
 foreach(var citis in citiesPerCountry)
 {
   Console.Writeline(Country.CountyName);
 }
}

Wednesday, January 4, 2012

code access security in asp.net

Using code access security we can convert the normal string format data into the encrypted format,the encrypted format data we can convert into the decrypted format (or) normal string format the code access security .we can implement by importing system.Security.Cryptography name space .The code access security depending on the hexa decimal byte values and encoding class.As per Microsoft the standard hexadecimal byte values are ox01 to ox16
using encoding class we can convert the normal string format data into the byte format,the byte format data we can convert into the normal string format,this class defined in the system.text name space.

TripleDESCryptoServiceProvider:
The class is used to encrypt the data,decrypt the data this class is depending on the hexa decimal byte values and encoding class

methods in TripleDES cryption:
1.Create Encryptor
2.create Decryptor
3.Cryptostream
Here i will shown how to encrypt and decrypt using TripleDES in asp.net.For this i have taken two button,one is for encryption and other one is for decryption
Example:

//name spaces which we have to add 
Using System.Security.Cryptography;
Using System.Text;
Using System.Io;


byte[] k=new byte[]{0x01,0x02,0x03,0x04,0x04..0x16}
byte[] i=new byte[]{0x01,0x02,0x03,0x04,0x04..0x16}
//button1_click
FileStream fs=new FileStream("c:/test.txt",FileMode.Create);
TripleDESCryptoServiceProvider tds=new TripleDESCryptoServiceProvider();
CryptoStream cs=new CryptoStream(fs,tds.CreateEecryptor(k,i),CryptoStreamMode.Write);
byte[]data=Encoding.ASCII.GetBytes("The  welcome")
cs.write(data,o,data.lenth)";
cs.close();
fs.close();

//button2-click
FileStream fs=new FileStream("c:/test.txt",FileMode.Open);
TripleDESCryptoServiceProvider tds=new TripleDESCryptoServiceProvider();
CryptoStream cs=new CryptoStream(fs,tds.CreateDecryptor(k,i),CryptoStreamMode.Read);
byte[]data=new byte[1000];
int len;
len=cs.read(data,o,data.lenth);
string s=Encoding.ASCII.GetString(data,o,data.lenth)
messagebox.show(s);
cs.write(data,o,data.lenthe)";
cs.close();
fs.close();

Tuesday, January 3, 2012

compute by in sql server

Drawback of group by is we can display information from only those columns that are used in group by and not possible to display the information from other columns available in the table that are not used in group by.When you want to display information from the columns in the table that are not used for grouping while grouping the rows,use "compute by"
syntax:
select statement computeby
ex:Display complete details of orders along with total quantity transfer to customers
select*from orders compute sum(quantity)
Display complete details of orders along with total quantity transfer to customers
select*from orders orederby customerno  compute sum(quantity) by customerno
Rule:A rule to use compute by is the columns that are specified in compute by must be in order by

Monday, January 2, 2012

Retrieve current user permissions in SQL

To get the list of permissions available for the current user on a Db or an object in the Db,use the function"fn-my-permissions".This function takes arguments,name of the DB or object and whether the first argument you specified is a DB or an object .
The fallowing example gets the DB level permissions on the DB for the current user
select *from fn-my-permissions('My DB','Database')
The fallowing example gets the object level permissions on orders table for the current user
select *from fn-my-permissions('orders','object')

Sunday, January 1, 2012

On-fly windows in Asp.net

If we want to create a window with no source file as it's content then we have to implement on-fly window concept(blank windows)This type of windows content is populated completely based on other programmer statements.The blank windows are not useful but by adding the reference to this blank window we can populate dynamic content .Here i will show how to create the blank window using java script.In java script we use same open method but this time with out file name and assign they open statement result to js variable.

on-fly windows in javacript

<form nane="form1">
username=<input name="t1" />
password=<input name="t2" />
<input name="b1" onclick="fly()" type="button" value="Click me" /> </form>
<script language="javascript">
function fly()
{
x=open("");
x.document.write("<h1>

welcome");
x.document.write("<img src=wondor.gif>");
}
</script>
//Here i will given more example script for area is covered on not.This can be use in above fly() method
x.document.write("welcome"+document.form.t1.value);

 x.document.write("<img src="http://www.blogger.com/wondor.gif" />");
 if(document.form.t2.value="12345")
 {
x.document.write("<img src="http://www.blogger.com/wondor.gif" />");
 x.document.write(" Area covered");
 }
 else
 {
 x.document.write("<img src="http://www.blogger.com/wondor.gif" />");
 x.document.write(" Area not covered");
 }
 }
The above on fly windows code create a blank window and populate static dynamic and decision content.Area not cover is decision base welcome is static username image is dynamic
Note:If you want to display the result in current window just do a small modification as below
this.document.write instead of x.document.write

Bel