Posts

Encrypt And Decrypt Example in JAVA

Security is the first concern when you develope application what have sensitive data such as account number, passport number , etc . Today i want to show example how to do simple encrypt and decrypt method in JAVA. In this tutorial i will use 3rd party library, you can download the library by the following link :  Common-Codecs-1.8 The import library : import org.apache.commons.codec.binary.Base64; import java.io.*; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import javax.swing.JOptionPane; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; The SharedVector   private static byte[] sharedvector = {     0x01, 0x02, 0x03, 0x05, 0x07, 0x0B, 0x0D, 0x11     }; The Encr

SqlClient Read Data in database using SqlDataReader - C#

This tutorial show how to read database using SqlDataReader in database using SqlClient driver to connect to database. Read here to read data in database and pass to DataTable Requirement in this tutorial are : using System.Data.SqlClient; using System.Data; The Example Read Data using SqlDataReader :             DataSet dataSetTable = new DataSet();             SqlConnection dbConn = new SqlConnection("<connection string>");             SqlCommand dbComm = new SqlCommand("<sql statement or procedure name>", dbConn);             SqlDataReader dbReader;             //set command type is procedure if you are using store procedure             //else remove this line             dbComm.CommandType = CommandType.StoredProcedure;             try             {                                dbConn.Open();                 dbReader = dbComm.ExecuteReader();                 if (dbReader.HasRows) //check if reader have any row                 {                    

SqlClient - Read Data From database and store into DataTable or DataSet - C#

This tutorial show how to read database and pass the value in DataTable or DataSet.  Requirement in this tutorial are : using System.Data.SqlClient; using System.Data; The sample code should be like this :             DataTable table = new DataTable();             SqlConnection dbConn = new SqlConnection("<connection string>");             SqlCommand dbComm = new SqlCommand("<sql statement or procedure name>", dbConn);                         //set command type is procedure if you are using store procedure             //else remove this line             dbComm.CommandType = CommandType.StoredProcedure;             try             {                 SqlDataAdapter dbAdapter = new SqlDataAdapter(dbComm);                 dbConn.Open();                 dbAdapter.Fill(table);             }             catch (SqlException sqlEx)             {                 MessageBox.Show(sqlEx.Message);                            }             finally             {          

How to detect page refresh in asp.net

Image
Page refresh is a one challenges that all web developers need to faces. It is because, when you have a button, and user click on the button and the process actually still processed at server side but the user refresh the page. The browser will ask user is either to resubmit or not. Normal user will always click resubmit. So the process actually repeat at server side also. This will cause a duplicate or redundant activity at server side which is will lead to incorrect result. Follow this example to detect the page refresh in ASP.NET . Create sample page name DetectPageRefresh.aspx   We will do logic to detect page refresh at the code behind. The  DetectPageRefresh.aspx   Page   <asp:Label ID="Label1" runat="server"></asp:Label>     <br />     <br />     <br />     <asp:Button ID="Button1" runat="server" Text="Do postback at server side"         onclick="Button1_Click" /> The Code Behind  priv

How To Show All session Key and Value In ASP.NET

Image
Session is a  powerful feature in web application to store information in server memory. by doing this, any data will be save temporary in server memory and can be access in the application. This is a advantage and disadvantage of Session : Advantages: It helps maintain user state and data all over the application. It is easy to implement and we can store any kind of object. Stores client data separately. Session is secure and transparent from the user. Disadvantages: Performance overhead in case of large volumes of data/user, because session data is stored in server memory. Overhead involved in serializing and de-serializing session data, because in the case of StateServer and SQLServer session modes, we need to serialize the objects before storing them.  More about session can read here In this example, i will show how to create simple page to show all session key and value of session key. : Requirement aspx page and code behind The Aspx Page      <h1>         Print All Sessi

Background Worker Example in C#

Image
How to avoid application "not responding" ..? if you developed one application  for example require to read some big data in database, read big file, or do some complicated task, you need to execute that task in a background worker. Background worker allow program do the task in a background process like picture above and wont let your application Not responding but actually the program is still work. The BackgroundWorker class allows you to run an operation on a separate, dedicated thread. Time-consuming operations like downloads and database transactions can cause your user interface (UI) to seem as though it has stopped responding while they are running. When you want a responsive UI and you are faced with long delays associated with such operations, the BackgroundWorker class provides a convenient solution. Read more about BackgroundWorker here Here the example : The Code Behind  private void button1_Click(object sender, EventArgs e)         {             Backgrou

All About GridView CRUD without 'C' (Read,Update,Delete) function ASP.Net

Image
Gridview is a powerful tools for developer to view the records from database, for example like user manager page. Today i want to show how to delete, and modify in gridview plus to have a user friendly viewing functionality about the a Total records that user want to show on GridView and total records of all data. Lets Try.. The ASP.NET Page  <asp:Label ID="LErrorMessage" ForeColor="Red" runat="server"></asp:Label>     <br />     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CssClass="mainTable"         BorderColor="Gray" BorderStyle="Solid" BorderWidth="1px"         AllowPaging="True" PageSize="15"         Width="864px" EmptyDataText="Tiada Rekod Dijumpai" OnRowDeleting="GridView1_RowDeleting"         OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDataBound="addJavascr