Profil de SantoshSantosh KumarPhotosBlogListesPlus Outils Aide
Photo 1 sur 36

Santosh Kumar

Occupation
Lieu

Santosh Kumar

The space where I am sharing my knowledge and thoughts

ASP.Net, Gridview paging simplified

 
Imports System
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Configuration
Imports MySql.Data.MySqlClient
 
Public Shared Sub BindGridView(ByRef faGV As GridView, ByVal faQry As String, Optional ByVal faIndex As Integer = 0)
    Dim dsPage As New DataSet
    If faIndex >= 0 Then faGV.PageIndex = faIndex
    BindDataSet(dsPage, faQry)
    faGV.DataSource = dsPage
    faGV.DataBind()
End Sub
 
Public Shared Sub BindDataSet(ByRef faDS As DataSet, ByVal faQry As String)
    Dim vMySqlConnection As MySqlConnection = Nothing
    Dim vMySqlDataAdapter As MySqlDataAdapter = Nothing
    Dim vMySqlCommand As MySqlCommand = Nothing
    Try
        vMySqlConnection = New MySqlConnection(ConfigurationManager.AppSettings("WebConfigMySql"))
        vMySqlCommand = vMySqlConnection.CreateCommand
        vMySqlCommand.CommandText = faQry
        vMySqlCommand.CommandType = CommandType.Text
        vMySqlConnection.Open()
        vMySqlDataAdapter = New MySqlDataAdapter(vMySqlCommand)
        faDS = New DataSet
        vMySqlDataAdapter.Fill(faDS)
 
    Catch ex As Exception
        faDS = Nothing
 
    Finally
        If Not vMySqlDataAdapter Is Nothing Then vMySqlDataAdapter.Dispose()
        If Not vMySqlCommand Is Nothing Then vMySqlCommand.Dispose()
        If Not vMySqlConnection Is Nothing Then vMySqlConnection.Dispose()
    End Try
End Sub
 
»»»»»»»   by Santosh Kumar ? Original @ http://santu4you.spaces.live.com
  

VB.Net, ASP.Net, Working with Cryptography

 
Imports System.IO
Imports Microsoft.VisualBasic
Imports System.Security.Cryptography
 
Public Class clsCrypto
 
    Private Shared Function GetCryptoKey() As String
        Dim vRet As String
        vRet = "jstbhgope"
        Return vRet
    End Function
 
 
    Private Shared Function GetCryptoBytes() As Byte()
        Dim vBytes() As Byte = {&H90, &H34, &H56, &H78, &H12, &HAB, &HCD, &HEF}
        Return vBytes
    End Function
 
 
    Public Shared Function DoEnCrypt(ByVal vStr As String) As String
 
        Dim vRgbKEY() As Byte = {}
        Dim vRgbIV() As Byte = GetCryptoBytes()
 
        Try
            vRgbKEY = System.Text.Encoding.UTF8.GetBytes(Left(GetCryptoKey(), 8))
 
            Dim des As New DESCryptoServiceProvider
            Dim inputByteArray() As Byte = Encoding.UTF8.GetBytes(vStr)
            Dim ms As New MemoryStream
            Dim cs As New CryptoStream(ms, des.CreateEncryptor(vRgbKEY, vRgbIV), CryptoStreamMode.Write)
            cs.Write(inputByteArray, 0, inputByteArray.Length)
            cs.FlushFinalBlock()
            Return Convert.ToBase64String(ms.ToArray())
 
        Catch ex As Exception
            Return ex.Message
 
        End Try
 
    End Function
 
 
    Public Shared Function DoDeCrypt(ByVal vStr As String) As String
        Dim vRgbKEY() As Byte = {}
        Dim vRgbIV() As Byte = GetCryptoBytes()
        Dim inputByteArray(vStr.Length) As Byte
 
        Try
            vRgbKEY = System.Text.Encoding.UTF8.GetBytes(Left(GetCryptoKey(), 8))
            Dim des As New DESCryptoServiceProvider
            inputByteArray = Convert.FromBase64String(vStr)
            Dim ms As New MemoryStream
            Dim cs As New CryptoStream(ms, des.CreateDecryptor(vRgbKEY, vRgbIV), CryptoStreamMode.Write)
 
            cs.Write(inputByteArray, 0, inputByteArray.Length)
            cs.FlushFinalBlock()
            Dim encoding As System.Text.Encoding = System.Text.Encoding.UTF8
 
            Return encoding.GetString(ms.ToArray())
 
        Catch ex As Exception
            Return ex.Message
 
        End Try
 
    End Function
 
End Class
  
»»»»»»»   by Santosh Kumar ? Original @ http://santu4you.spaces.live.com
 

Oracle, How to select records from record no N1 to N2

 
SQL> SELECT ROWNUM, E.* FROM EMP E /*This is the table*/;
 
    ROWNUM      EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
         1       7369 SMITH      CLERK           7902 17-DEC-80       -800                    20
         2       7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
         3       7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
         4       7566 JONES      MANAGER         7839 02-APR-81       2975                    20
         5       7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
         6       7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
         7       7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
         8       7788 SCOTT      ANALYST         7566 09-DEC-82       3000     5000.5         20
         9       7839 KING       PRESIDENT            17-NOV-81       5000                    10
        10       7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
        11       7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
        12       7900 JAMES      CLERK           7698 03-DEC-81        950                    30
        13       7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
        14       7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
 
14 rows selected.
 
SQL> SELECT * FROM( /*This will select 5th to 10th records*
  2  SELECT ROWNUM RN, E.* FROM EMP E WHERE ROWNUM  <= 10
  3  ) WHERE RN  >= 5
  4  /
 
        RN      EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
         5       7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
         6       7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
         7       7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
         8       7788 SCOTT      ANALYST         7566 09-DEC-82       3000     5000.5         20
         9       7839 KING       PRESIDENT            17-NOV-81       5000                    10
        10       7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
 
6 rows selected.
  
»»»»»»»   by Santosh Kumar ? Original @ http://santu4you.spaces.live.com
 

Oracle, How to select last N records

 
SQL> SELECT ROWNUM, E.* FROM EMP E /*This is the table*/;
 
    ROWNUM      EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
         1       7369 SMITH      CLERK           7902 17-DEC-80       -800                    20
         2       7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
         3       7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
         4       7566 JONES      MANAGER         7839 02-APR-81       2975                    20
         5       7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
         6       7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
         7       7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
         8       7788 SCOTT      ANALYST         7566 09-DEC-82       3000     5000.5         20
         9       7839 KING       PRESIDENT            17-NOV-81       5000                    10
        10       7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
        11       7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
        12       7900 JAMES      CLERK           7698 03-DEC-81        950                    30
        13       7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
        14       7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
 
14 rows selected.
 
SQL> SELECT * FROM( /*This will select last five records*/
  2      SELECT * FROM(
  3          SELECT ROWNUM RN, E.* FROM EMP E
  4      ) ORDER BY RN DESC
  5  ) WHERE ROWNUM  <= 5
  6  /
 
        RN      EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
        14       7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
        13       7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
        12       7900 JAMES      CLERK           7698 03-DEC-81        950                    30
        11       7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
        10       7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
 
»»»»»»»   by Santosh Kumar ? Original @ http://santu4you.spaces.live.com
 

Oracle, How to select random records

 
SQL> SELECT ROWNUM, E.* FROM EMP E /*This is the table*/;
 
    ROWNUM      EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
         1       7369 SMITH      CLERK           7902 17-DEC-80       -800                    20
         2       7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
         3       7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
         4       7566 JONES      MANAGER         7839 02-APR-81       2975                    20
         5       7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
         6       7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
         7       7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
         8       7788 SCOTT      ANALYST         7566 09-DEC-82       3000     5000.5         20
         9       7839 KING       PRESIDENT            17-NOV-81       5000                    10
        10       7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
        11       7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
        12       7900 JAMES      CLERK           7698 03-DEC-81        950                    30
        13       7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
        14       7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
 
14 rows selected.
 
SQL> SELECT ROWNUM, E.* FROM EMP E ORDER BY DBMS_RANDOM.VALUE /*This will randimise the rows*/;
 
    ROWNUM      EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
         3       7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
        12       7900 JAMES      CLERK           7698 03-DEC-81        950                    30
         4       7566 JONES      MANAGER         7839 02-APR-81       2975                    20
         1       7369 SMITH      CLERK           7902 17-DEC-80       -800                    20
         6       7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
        13       7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
         5       7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
        14       7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
         8       7788 SCOTT      ANALYST         7566 09-DEC-82       3000     5000.5         20
         2       7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
        10       7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
        11       7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
         7       7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
         9       7839 KING       PRESIDENT            17-NOV-81       5000                    10
 
14 rows selected.
 
SQL> SELECT ROWNUM, E.* FROM( /*This will select 5 random records*/
  2  SELECT * FROM EMP ORDER BY DBMS_RANDOM.VALUE
  3  ) E WHERE ROWNUM <= 5
  4  /
 
    ROWNUM      EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
         1       7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
         2       7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
         3       7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
         4       7788 SCOTT      ANALYST         7566 09-DEC-82       3000     5000.5         20
         5       7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
  
»»»»»»»   by Santosh Kumar ? Original @ http://santu4you.spaces.live.com
 
 
Thanks for visiting!
Veuillez patienter...
Le commentaire entré est trop long. Raccourcissez-le.
Vous n'avez rien entré. Réessayez.
Il est actuellement impossible d'ajouter votre commentaire. Réessayez plus tard.
Pour ajouter un commentaire, tu dois avoir l'autorisation de tes parents. Demander l'autorisation
Tes parents ont désactivé les commentaires.
Il est actuellement impossible de supprimer votre commentaire. Réessayez plus tard.
Vous avez dépassé le nombre maximal de commentaires qu'il est possible d'envoyer le même jour. Réessayez dans 24 heures.
Votre compte a pu laisser les commentaires désactivés parce que nos systèmes indiquent que vous risquez d'arroser d'autres utilisateurs de messages. Si vous pensez que votre compte a été désactivé par erreur, contactez l'assistance en ligne de Windows Live.
Effectuez la vérification de sécurité ci-dessous pour finaliser l'envoi de votre commentaire.
Les caractères entrés pour la vérification de sécurité doivent correspondre à ceux de l'image ou du fichier audio.