Google+ Followers

Connect

Get Updates Via Email

Enter your email address:

Delivered by FeedBurner

Saturday, 16 November 2013

How to create and execute stored procedure in linux mysql command? [ Linux Mysql: Create and execute stored procedures ]

Sql Scripts for creating stored procedures:

mysql > delimiters //
mysql > use userDB;
          > select database();
          > create procedure userdbprdt()
          >  begin
          >  select u.id,u.name,u.username,ur.product from usertbl u join userproduct ur where u.id=ur.id;             > end//


Sql script for executing stored procedure

mysql> call userdbprdt()//

Java Swing MySql JDBC: insert data into database

Program

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

public class insertswing implements ActionListener
{
  JFrame fr;JPanel po;
  JLabel l1,l2,main;
  JTextField tf1,tf2;
  GridBagConstraints gbc;
  GridBagLayout go;
  JButton ok,exit;

public insertswing(){
fr=new JFrame("New User Data ");
Font f=new Font("Verdana",Font.BOLD,24);
po=new JPanel();
fr.getContentPane().add(po);
fr.setVisible(true);
fr.setSize(1024,768);
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
po.setBackground(Color.WHITE);
go=new GridBagLayout();
gbc=new GridBagConstraints();
po.setLayout(go);
main=new JLabel("Enter User Details ");
main.setFont(f);
l1=new JLabel("Name  :");tf1=new JTextField(20);
l2=new JLabel("User Name  :");tf2=new JTextField(20);
ok=new JButton("Accept");
exit=new JButton("Exit");

gbc.anchor=GridBagConstraints.NORTH;gbc.gridx=5;gbc.gridy=0;
go.setConstraints(l1,gbc);po.add(main);

gbc.anchor=GridBagConstraints.WEST;gbc.gridx=5;
gbc.gridy=5;go.setConstraints(l1,gbc);po.add(l1);


gbc.anchor=GridBagConstraints.WEST;gbc.gridx=10;gbc.gridy=5;
go.setConstraints(tf1,gbc);po.add(tf1);

gbc.anchor=GridBagConstraints.WEST;gbc.gridx=5;gbc.gridy=10;
go.setConstraints(l2,gbc);po.add(l2);

gbc.anchor=GridBagConstraints.WEST;gbc.gridx=10;
gbc.gridy=10;go.setConstraints(tf2,gbc);po.add(tf2);

gbc.anchor=GridBagConstraints.WEST;gbc.gridx=10;gbc.gridy=90;
go.setConstraints(ok,gbc);po.add(ok);ok.addActionListener(this);

gbc.anchor=GridBagConstraints.WEST;gbc.gridx=11;gbc.gridy=90;
go.setConstraints(exit,gbc);po.add(exit);
exit.addActionListener(this);

}

@Override
public void actionPerformed(ActionEvent ev)
{
    if(ev.getSource()==ok)

    {
        try{
Connection con;JLabel last =new JLabel("Data inserted successfully");
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection
("jdbc:mysql://localhost/userDB","root","root");
 PreparedStatement ps=con.prepareStatement
("Insert into usertbl values(default,?,?)");
String id=tf1.getText();String sname=tf2.getText();
ps.setString(1,id);ps.setString(2,sname);
ps.executeUpdate();con.close();
tf1.setText("");tf2.setText("");
    JOptionPane.showMessageDialog(fr, "Data inserted successfully.");
        }
catch(Exception e){
    System.out.println("ERROR  "+e);
}
    }
if(ev.getSource() == exit){fr.dispose();

}
}


    public static void main(String a[]){
    new insertswing();
    }

}






output

 1. Adding values and data inserted successfully popup message




 2. Checking inserted value in database table


MySql linux terminal Commands: Basic commands to create and drop databases commands

1. Login on mysql  command



mysql -u root -h localhost -p








2. Check Status

mysql> status










3. show databases

mysql> show databases;














4. Show variables

mysql> show variables;



5. Show processlist

mysql> show processlist;



6. Using and selecting system already available mysql database

mysql> use mysql;
mysql> select database();


7. select user table in mysql database

mysql> select Host, User from user
or

mysql> select Host, User from mysql.user



8. Create database and display it

mysql> create database tempDB;
mysql> show databases;
mysql> use tempDB;
mysql> select database();



9. Drop database

 mysql> drop database tempDB;
 mysql> show databases;



10. exit  mysql 

 mysql> exit


 

Friday, 15 November 2013

Data Structure and Algorithms : Queue Program in Java

Program:

public class queuepgm {
private int maxSize;
private long[] queArray;
private int front;
private int rear;
private int nItems;

public queuepgm(int s)

{
maxSize = s;
queArray = new long[maxSize];
front = 0;
rear = -1;
nItems = 0;
}

public void enqueue(long j)

{
if(rear == maxSize-1)
rear = -1;
queArray[++rear] = j;
nItems++;
}

public long dequeue()
{
long temp = queArray[front++];
if(front == maxSize)
front = 0;
nItems--;
return temp;
}
public long peekFront()

{
    return queArray[front];
}
public boolean isEmpty()      
{
return (nItems==0);
}
public boolean isFull()
{
return (nItems==maxSize);
}
public int size()
{
return nItems;
}
public static void main(String[] args)
{
queuepgm theQueue = new queuepgm(5); // queue holds 5 items
theQueue.enqueue(10);
theQueue.enqueue(20);
theQueue.enqueue(30);
theQueue.enqueue(40);
System.out.println("Dequeue Values: FIFO");
while( !theQueue.isEmpty() )
{
long n = theQueue.dequeue();
System.out.print(n+"\n");

}
}

}

Output:


Data Structure and Algorithms : Stack Program in Java

Program

public class stackpgm {
private int maxSize;
private long[] stackArray;
private int top;
public stackpgm(int s)

{
maxSize = s;

stackArray = new long[maxSize];
top = -1;

}

public void push(long j)

{
    if(!isFull())
    {
      stackArray[++top] = j;
    }

}
public long pop()
{
   
      return stackArray[top--];  
   
     
}

public long peek()

{
return stackArray[top];
}

public boolean isEmpty()

{
return (top == -1);
}

public boolean isFull()
{
return (top == maxSize-1);
}

public static void main(String[] args)
{
stackpgm theStack = new stackpgm(10);
theStack.push(1);
theStack.push(2);
theStack.push(3);
theStack.push(4);
System.out.println("Pop up values");
while( !theStack.isEmpty() )
{
long value = theStack.pop();
System.out.print(value+"\n");
}
}


}

Output


Head and Tail Commands in Linux


Head Command

Description : prints output of first part of the file by default it will print first 10 lines

Syntax : head filename

examples:

1.  head upcasting.java


it will print first 10 lines of the file upcasting.java by default.

2. head -n 50 upcasting.java
 it will print first 50 lines of the file upcasting.java.

3. head upcasting.java downcasting.java
it will print first 10 line of the 2 files upcasting.java and downcasting.java.

4. head *.java
it will print all the java files first 10 lines.

5. head *.java *.class
it will print all the java and class files first 10 lines.


Tail Command:

Description : prints output of last part of the file by default it will print last 10 lines

Syntax : tail filename

Examples:

1. tail upcasting.java
it will print last 10 lines of the file upcasting.java by default.

2. tail -n 50 upcasting.java
 it will print last 50 lines of the file upcasting.java.

3. tail upcasting.java downcasting.java
it will print last 10 line of the 2 files upcasting.java and downcasting.java.

4. tail *.java
it will print all the java files last 10 lines.

5. tail *.java *.class
it will print all the java and class files last 10 lines.

Practice Examples:

1. How to Print the 11th line of the file ?

    head -n 11 upcasting.java | tail -n 1

2. How to print lines from 5 to 11th of the file ?

    head -n 11 upcasting.java | tail -n 5

3.  How to print number of lines head and tail command file (by default it will  print 10 lines)?
   
    head upcasting.java | wc -l
    tail upcasting.java | wc -l


    both will return 10

    head -n 20 upcasting.java | wc -l
    tail -n 20 upcasting.java | wc -l


   both will return 20

   for number of word wc -w and number of characters wc -c

   head upcasting.java | wc -c
   it will print number of first 10 lines characters in digits

   tail upcasting.java | wc -c
   it will print number of last 10 lines characters in digits
 

   head upcasting.java | wc -w
   it will print number of first 10 lines words in digits

   tail upcasting.java | wc -w
   it will print number of last 10 lines words in digits

4. How to get First and last 5 files of java in a java directory?

   ls *.java | tail -n 5  
   ls *.java | head -n 5
 
   ls -l *.java | tail -n 5  
   ls -l *.java | head -n 5

5. ls -la *.class | tail -n 12 | wc -l  it will return 12

6.  ls -la *.class | tail -n 12
it will shows last 12 class files list

7.  ls -la *.class | head -n 12 
it will shows first 12 class files list.  

8.      head -c 10 downcasting.java
9.      tail -c 10 downcasting.java
10.   head -c 400  downcasting.java | tail -n 3

(updates still come)

Monday, 11 November 2013

Linux Terminal Commands

Install Command

sudo apt-get install <package-name>
Example:
Installing vlc media player

sudo apt-get install vlc



ls Command

ls -l
list folders and files with read write permissions and user groups

ls -aThis command shows hidden files and folders

ls -al
ls -la


Clear Command

clear

this command clears the screen

Manual Command

man <command>

this command shows manual of the commands

example man ls shows manual command of ls


q to quit the manual screen back to terminal commands

ifconfig command

ifconfig command ip network address details

netstat command

netstat command used to show network status like ip addresses of local and foreign; port, pid, network protocols

cat Command 

cat command concatenate files and print on the standard output.























Java Program: Down casting Inheritence

Program

public class downcasting {
   public static void main(String[] args)
    {
     fordd f;
     benzz b;
     BMWw bm;
     carr c,cc,ccc;
     c=new fordd();
     cc=new benzz();
     ccc=new BMWw();
     f=(fordd)c; // downcasting or narrowing or specialization
     b=(benzz)cc;
     bm=(BMWw)ccc;
     f.car();
     b.car();
     bm.car();
    }
}
class carr
{
    void car()
    {
        System.out.println("This super class car method");
    }
}
class fordd extends carr
{
    void car()
    {
        System.out.println("This sub class Ford car method");
    }
}
class benzz extends carr
{
     void car()
    {
        System.out.println("This sub class Benz car method");
    }
}
class BMWw extends carr
{
     void car()
    {
        System.out.println("This sub class BMW car method");
    }

}

Output



Java Program: Up casting Program in inheritance

Program

public class upcasting {
   public static void main(String[] args)
    {
     car c,cc,ccc,o;
     o=new car();
     o.car(); //no casting
     c=(car)new ford(); //upcasting ford sub class to super class
     c.car();
     cc=(car)new benz();//upcasting ford sub class to super class
     cc.car();
     ccc=(car)new BMW();//upcasting ford sub class to super class      
     ccc.car();
   
    }
}
class car
{
    void car()
    {
        System.out.println("This super class car method");
    }
}
class ford extends car
{
    @Override
    void car()
    {
        System.out.println("This sub class Ford car method");
    }
}
class benz extends car
{
     @Override
    void car()
    {
        System.out.println("This sub class Benz car method");
    }
}
class BMW extends car
{
     @Override
    void car()
    {
        System.out.println("This sub class BMW car method");
    }

}

Output



Java Program: Inheritance Super Keyword

Program

class inheritance
{
 public static void main(String[] args)
 {
  apple a=new apple();
  a.disp();
 }
}
class fruit
{
 String f="fruit";
 public void disp()
 {
  System.out.println("Base Class "+f);
 }
}
class apple extends fruit
{
 String f="Apple";
 public void disp()
 {
  System.out.println("Derived Class  "+f);
  super.disp();
  System.out.println("Super Class "+super.f);
 }

}

Output


Java Program: File I/O Fileoutputstream to create file

Program

import java.io.*;
public class createfile {
    public static void main(String[] args)
    {
        try
        {
        createfile();
        }
        catch(Exception ex)
        {
            System.out.println("File Exceptio occured");
        }    
    }
    public static void createfile() throws java.io.IOException
    {
        DataInputStream d=new DataInputStream(System.in);
        FileOutputStream f=new FileOutputStream("jack.txt",true);
        BufferedOutputStream b=new BufferedOutputStream(f,1024);
        System.out.println("Enter $ at the end to finish text");
        char c;
        while((c=(char)d.read())!='$')
        {
            b.write(c);          
        }
        b.close();
    }

}

Output



Java Program: AWT Frame Closing Event

Program

import java.awt.*;
import java.awt.event.*;
public class awtexample extends Frame{
    public static void main(String[] args)
    {
        Frame f= new Frame("New Frame");
        f.setSize(400, 500);
        f.setVisible(true);
        f.addWindowListener(new WindowAdapter(){
        public void windowClosing(WindowEvent e)
        {
        System.exit(0);
        }
     });
    }
}

Output




Sunday, 10 November 2013

Java Program: Multi Thread optimum way utilize CPU time using Thread(Runnable object, String thread_name)

Program

import java.util.logging.Level;
import java.util.logging.Logger;

class ThreadRunnnable {
    public static void main(String[] args)
    {
       
       new ThreadRun();
       new ThreadRunn();
       System.out.println("Main Thread Starts");
        for(int i=1;i<=5;i++)
        {
            System.out.println(i);
            try {
                Thread.sleep(1500);
            } catch (InterruptedException ex) {
                Logger.getLogger(ThreadRun.class.getName()).log(Level.SEVERE, null, ex);
            }
        }      
     
       
    }
}
class ThreadRun implements Runnable
{
    ThreadRun()
    {
       
        Thread t=new Thread(this,"Thread1");
        t.start();
        System.out.println("Thread 1");
       
    }
    @Override
    public void run()
    {
        for(int i=1;i<=5;i++)
        {
            System.out.println(i);
            try {
                Thread.sleep(500);
            } catch (InterruptedException ex) {
                Logger.getLogger(ThreadRun.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
   
    }  
               
}

class ThreadRunn implements Runnable
{
   
    ThreadRunn()
    {
       
        Thread t=new Thread(this,"Thread1");
        t.start();
        System.out.println("Thread 2");
       
    }
    @Override
    public void run()
    {
        for(int i=1;i<=5;i++)
        {
            System.out.println(i);
            try {
                Thread.sleep(300);
            } catch (InterruptedException ex) {
                Logger.getLogger(ThreadRun.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
               
    }  
               
}


Output

Thread 1
Thread 2
Main Thread Starts
Main Thread 1
Thread 2 1
Thread 1 1
Thread 2 2
Thread 2 3
Thread 2 4
Main Thread 2
Thread 2 5
Thread 1 2
Main Thread 3
Main Thread 4
Thread 1 3
Main Thread 5
Thread 1 4
Thread 1 5

Output of this program not unique it always random, because it depends on thread sleep method due to multiple threads, one thread waits and other threads are executing that's why java multi threads utilize the cpu time in optimum way

Java Program: Thread using Runnable interface program

Program

import java.util.logging.Level;
import java.util.logging.Logger;

class ThreadRunnnable {
    public static void main(String[] args)
    {      
       new ThreadRun();
       new ThreadRunn();
       System.out.println("Main Thread Starts");
        for(int i=1;i<=5;i++)
        {
            System.out.println(i);
            try {
                Thread.sleep(1500);
            } catch (InterruptedException ex) {
                Logger.getLogger(ThreadRun.class.getName()).log(Level.SEVERE, null, ex);
            }
        }      
     
    }
}
class ThreadRun implements Runnable
{
    ThreadRun()
    {      
        Thread t=new Thread();
        t.start();
        System.out.println("Thread 1");
        run();
    }
    @Override
    public void run()
    {
        for(int i=1;i<=5;i++)
        {
            System.out.println(i);
            try {
                Thread.sleep(500);
            } catch (InterruptedException ex) {
                Logger.getLogger(ThreadRun.class.getName()).log(Level.SEVERE, null, ex);
            }
        }  
    }                
}
class ThreadRunn implements Runnable
{  
    ThreadRunn()
    {      
        Thread t=new Thread();
        t.start();
        System.out.println("Thread 2");
        run();
    }
    @Override
    public void run()
    {
        for(int i=1;i<=5;i++)
        {
            System.out.println(i);
            try {
                Thread.sleep(300);
            } catch (InterruptedException ex) {
                Logger.getLogger(ThreadRun.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
             
    }  
}

Output

Thread 1
1
2
3
4
5
Thread 2
1
2
3
4
5
Main Thread Starts
1
2
3
4

5

Java Program: Thread in swing implements Runnable interface and SwingUtilities

Program
import javax.swing.*;
public class SwingThread extends JFrame {
    public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        final JFrame f = new JFrame("Swing using Thread Frame 1");
        f.setSize(600, 400);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
     
        final JFrame fr = new JFrame("Swing using Thread Frame 2");
        fr.setSize(600, 600);
        fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        fr.setVisible(true);
      }
    });
    }
 

}

Output:


Java Program: Simple Thread Example

public class threadexample {
    public static void main(String args[])
    {
        Thread t=Thread.currentThread();
        System.out.println("Current Thread: "+t);
        t.setName("Thread Example");
        System.out.println("Current Thread Name changed as: "+t);
    }

}

output

Java Program: Swap two numbers without temp variable

import java.io.*;
public class Swapwithouttemp {
    public static void main(String[] args) throws IOException
    {
        System.out.println("Enter first number");
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int x=Integer.parseInt(br.readLine());    
        System.out.println("Enter second number");
        BufferedReader brr=new BufferedReader(new InputStreamReader(System.in));
        int y=Integer.parseInt(brr.readLine());        
        new swap(x,y);
    }
}
class swap
{  
    swap(int a, int b) throws IOException          
    {
        System.out.println("Before swapped values a= "+a+"\tb= "+b );
        a=a+b;
        b=a-b;
        a=a-b;
        System.out.println("After swapped values a= "+a+"\tb= "+b );
    }
}

Java Program: User defined input using BufferedReader, Checking Employee Age

import java.io.*;
public class EmployeeAgeCheck {
    public static void main(String[] args) throws IOException
    {
        EmployeeData e=new EmployeeData();
        e.getdetails();
        e.checkage();      
    }
}
class EmployeeData
{
    private String name;
    private int age;

    public void getdetails() throws java.io.IOException
    {
        // user defined input at runtime
        BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter name");
        name=buf.readLine();
        System.out.println("Enter Age");
        age=Integer.parseInt(buf.readLine());
    }
    public void checkage()
    {
        if(age<=30)
        {
            System.out.println(name+ " ,You're Junior Employee");
        }
        else
        {
            System.out.println(name+ " ,You're Senior Employee");
        }
    }
}

Java Program : Default and Parameterized Constructor

public class constructorexample {
    public static void main(String[] args)
    {
        personcon kumaran=new personcon();
        kumaran.display();
        personcon jannu=new personcon("Jannu",22);
        jannu.display();
    }
}

class personcon
{
    private String name;
    private int age;
    //default constructor
    personcon()
    {
        name="kumaran";
        age=23;
    }
   //parameterized constructor
    personcon(String n,int a)          
    {
        name=n;
        age=a;
    }
    public void display()
    {
        System.out.println("Name: "+name+"\t Age: "+age);
    }
}

Saturday, 9 November 2013

How to download google chrome browser in linux using terminal command?

Step 1: Download Google Chrome

For 32 bit version

$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_i386.deb

For 64 bit version

$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

Step 2: Install .deb file

For 32 bit version

$ sudo dpkg -i google-chrome-stable_current_i386.deb

For 64 bit version

$ sudo dpkg -i google-chrome-stable_current_amd64.deb
Issues:

if you get any error while installing or downloading just use this below command to clear the issues

1. $ sudo apt-get update
2. $ sudo apt-get upgrade


3. $ sudo apt-get -f install
After installation check it google chrome in linux dash home search:




Thursday, 7 November 2013

How to check CPU usage in Linux OS?


Generally top is a command to check CPU usage on any OS.

top command


































































htop Command

In Linux Terminal command to CPU usage htop is another to do the task

but before install htop as: Sudo apt-get install htop in terminal then after use htop command other than iostat, /proc/meminfo,mpstat are the commands to be used to check CPU and memory usages












Friday, 18 October 2013

Compress Data using ASCII Values and Decompress data to get back original ASCII




public class StrAscii {
    
    public static void main(String[] args)
    {
     
        StrAscii.stringToBytesASCII("Apple");
    }
    
    public static byte[] stringToBytesASCII(String str) {
 byte[] b = new byte[str.length()];
 for (int i = 0; i < b.length; i++) {
     System.out.println("Before Ascii "+i+" ="+b[i]);
  b[i] = (byte) str.charAt(i);
  System.out.println("After Ascii "+i+" ="+b[i]);

  StrAscii sa=new StrAscii();
  
  System.out.println("Compressed data Bytes "+i+" ="+sa.compressbyte(b[i]));
  System.out.println("Compressed data Slots "+i+" ="+sa.compressslot(b[i]));
  System.out.println("Decompressed data "+i+" ="+ (sa.compressbyte(b[i])*9+sa.compressslot(b[i])));
 }

 return b;
}
 public long compressslot(long x)
 {
     x = x%9;
     return x;
 }
 public long compressbyte(long y)
 {
     y = y/9;
     return y;
 }
}

Output

Before Ascii 0 =0
After Ascii 0 =65
Compressed data Bytes 0 =7
Compressed data Slots 0 =2
Decompressed data 0 =65
Before Ascii 1 =0
After Ascii 1 =112
Compressed data Bytes 1 =12
Compressed data Slots 1 =4
Decompressed data 1 =112
Before Ascii 2 =0
After Ascii 2 =112
Compressed data Bytes 2 =12
Compressed data Slots 2 =4
Decompressed data 2 =112
Before Ascii 3 =0
After Ascii 3 =108
Compressed data Bytes 3 =12
Compressed data Slots 3 =0
Decompressed data 3 =108
Before Ascii 4 =0
After Ascii 4 =101
Compressed data Bytes 4 =11
Compressed data Slots 4 =2
Decompressed data 4 =101

Apple ===> Array [0... 4 ] => 0 = A =65, 1=p=112, 2=p=112, 3=l=108,4=e=101.

After Compression process
  compressing Data byte Values  { 7,12,12,12,11}
  compressing Data Slot Values  { 2,4,4,0,2 }

Decompression process very simple just like this =>(sa.compressbyte(b[i])*9+sa.compressslot(b[i]))=>7*9+2=> 65 =>A

Thursday, 22 August 2013

Four Sequential or series Squared Numbers Formula's in two cases

In this I've observed and innovated new shortcut Math formula of Four Sequential or series Squared Numbers Formula's in two cases;

Case 1: Only applicable for positive numbers;
Case 2: it will be applicable both negative and positive numbers in those series;

Condition : d- difference must be unique;

See below pictures that I've made it in two formulas


Monday, 8 July 2013

Login and Registration forms in C# windows application with Back end Microsoft SQL Server for data access


In this article, I'm gonna share about how to make login and register form with MS SQL database;

1. Flow Chart Logic





















2. Normal Features




3. Form Designs
Login Form Design


Sign in Form Design



Password Retrieve Form



4. Database Design and SQL queries and Stored Procedure

Create new Database as "schooldata"
create table registerdata
(
 ID int identity,
 Username nvarchar(100),
 Password nvarchar(100),
 Fullname  nvarchar(100),
 MobileNO nvarchar(100),
 EmailID nvarchar(100) 
)

select * from registerdata

create procedure regis
(
 @Username as nvarchar(100),
 @Password as nvarchar(100),
 @Fullname as nvarchar(100),
 @MobileNO as nvarchar(100),
 @EmailID as nvarchar(100) 
)
as begin
insert into registerdata (Username, Password, Fullname, MobileNO,EmailID)
values (@Username, @Password, @Fullname, @MobileNO, @EmailID)
end


5. App.config Settings

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <configSections>
  </configSections>
  <connectionStrings>
    <add name="ConnData"
        connectionString="Data Source=localhost\sqlexpress;Initial Catalog=Schooldata;Integrated Security=True"
        providerName="System.Data.SqlClient" />
  </connectionStrings>
  
</configuration>


6. SignIn Form Coding

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Net;
using System.Collections.Specialized;

namespace SchoolData
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SigninForm sf = new SigninForm();
            sf.Show();
            this.Hide();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            if ((textBox1.Text != "") && (textBox2.Text != ""))
            {
                string constring = ConfigurationManager.ConnectionStrings["ConnData"].ConnectionString;
                SqlConnection con = new SqlConnection(constring);
                string q = "select * from registerdata where Username = @Username and Password = @Password ";
                SqlCommand cmd = new SqlCommand(q, con);
                cmd.Parameters.AddWithValue("@Username", this.textBox1.Text);
                cmd.Parameters.AddWithValue("@Password", this.textBox2.Text);
                con.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    if (dr.HasRows == true)
                    {
                        MessageBox.Show("Login Successfully Done");
                    }
                }
                if (dr.HasRows == false)
                { MessageBox.Show("Access Denied, password username mismatched"); }
            }
            else { MessageBox.Show("Enter username and password"); }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            RetrievePwdForm rf = new RetrievePwdForm();
            rf.Show();
            this.Hide();
        }
        
    }
}


7. Register Form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Net;
using System.Collections.Specialized;

namespace SchoolData
{
    public partial class SigninForm : Form
    {
        public SigninForm()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }
        //checking whether username already exist
        public void UserNameCheck()
        {
            string constring = ConfigurationManager.ConnectionStrings["ConnData"].ConnectionString;
            SqlConnection con = new SqlConnection(constring);
            SqlCommand cmd = new SqlCommand("Select * from registerdata where Username= @Username", con);
            cmd.Parameters.AddWithValue("@Username", this.textBox1.Text);
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                if (dr.HasRows == true)
                {
                    MessageBox.Show("Username = "+ dr[1].ToString() +" Already exist");
                    break;
                }
            }
            //return textBox1.Text  ;
        }
        // clear all values in textbox
        public void clearall()
        {
            textBox1.Text = " ";
            textBox2.Text = " ";
            textBox3.Text = " ";
            textBox4.Text = " ";
            textBox5.Text = " ";

        }
        //checking whether mobile number already exist
        public void MobileNOCheck()
        {
            string constring = ConfigurationManager.ConnectionStrings["ConnData"].ConnectionString;
            SqlConnection con = new SqlConnection(constring);
            SqlCommand cmd = new SqlCommand("Select * from registerdata where MobileNO= @MobileNO", con);
            cmd.Parameters.AddWithValue("@MobileNO", this.textBox4.Text);
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                if (dr.HasRows == true)
                {
                    MessageBox.Show("MobileNO = " + dr[4].ToString() + "is Already exist");
                    break;
                }
            }
            //return textBox4.Text;
        }
        public void datastore()
        {

            string Fname, Sname, Fullname, MobileNO, EmailID;
            Fname = textBox1.Text;
            Sname = textBox2.Text;
            Fullname = textBox3.Text;
            MobileNO = textBox4.Text;
            EmailID = textBox5.Text;
            try
            {
                string constring = ConfigurationManager.ConnectionStrings["ConnData"].ConnectionString;

                /* Declaring Connection Variable */
                SqlConnection con = new SqlConnection(constring);

                /* Checking Connection is Opend or not If its not open the Opens */
                if (con.State != ConnectionState.Open)
                    con.Open();

                /* Calling Stored Procedure as SqlCommand */
                SqlCommand cmd = new SqlCommand("regis", con);
                cmd.CommandType = CommandType.StoredProcedure;

                /* Passing Input Parameters with Command */
                cmd.Parameters.AddWithValue("@Username", Fname);
                cmd.Parameters["@Username"].Direction = ParameterDirection.Input;

                cmd.Parameters.AddWithValue("@Password", Sname);
                cmd.Parameters["@Password"].Direction = ParameterDirection.Input;

                cmd.Parameters.AddWithValue("@Fullname", Fullname);
                cmd.Parameters["@Fullname"].Direction = ParameterDirection.Input;

                cmd.Parameters.AddWithValue("@MobileNO", MobileNO);
                cmd.Parameters["@MobileNO"].Direction = ParameterDirection.Input;

                cmd.Parameters.AddWithValue("@EmailID", EmailID);
                cmd.Parameters["@EmailID"].Direction = ParameterDirection.Input;

                /* Executing Stored Procedure */
                cmd.ExecuteNonQuery();
                con.Close();
                MessageBox.Show("Data Inserted Succesfully");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
             
        }
        public void registerdata()
        {       datastore();
                this.Hide();
                LoginForm lf = new LoginForm();
                lf.Show();
            
        }
        private void button1_Click(object sender, EventArgs e)
        {
            registerdata();
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            //UserNameCheck();
            //clearall();
        }

        private void textBox4_KeyDown(object sender, KeyEventArgs e)
        {
            //MobileNOCheck();
            //clearall();
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            //UserNameCheck();
            //clearall();
        }

        private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
        {
            //MobileNOCheck();
            //clearall();
        }

        private void textBox4_KeyUp(object sender, KeyEventArgs e)
        {
            //MobileNOCheck();
            //clearall();
        }
        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            //UserNameCheck();
            //clearall();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            UserNameCheck();
           
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {
           // MobileNOCheck();
           
        }

        private void textBox4_TextChanged_1(object sender, EventArgs e)
        {
            MobileNOCheck();
        }
    }
}

8. Retrieve Password Form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Net;
using System.Collections.Specialized;

namespace SchoolData
{
    public partial class RetrievePwdForm : Form
    {
        public RetrievePwdForm()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.Hide();
            LoginForm lf = new LoginForm();
            lf.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string constring = ConfigurationManager.ConnectionStrings["ConnData"].ConnectionString;
            SqlConnection con = new SqlConnection(constring);
            SqlCommand cmd = new SqlCommand("Select * from registerdata where MobileNO= @MobileNO", con);
            cmd.Parameters.AddWithValue("@MobileNO", this.textBox1.Text);
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                if (dr.HasRows == true)
                {
                    string str = "Your Password = ";
                    label2.Text=str +  dr[2].ToString();
                }
            }
        }
    }
}

Output


a) Register New User and store into database






b) Check Username already Exist

C) Check Mobile Number Already Exist


D) Forget Password



Finally Login Successfully done