Sunday, 23 August 2015

INSERT-3 TIER

INSERT
DAL:
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Data.SqlClient;


public class insertdal
{
      SqlCommand cmd;

      connectiondal conobj = new connectiondal();

      public void insertdetails(string name, int age, System.DateTime dob)
      {
            cmd = new SqlCommand("stp_insert", conobj.Connection);
            cmd.CommandType = CommandType.StoredProcedure;

            try {

                  cmd.Parameters.AddWithValue("@name", name);
                  cmd.Parameters.AddWithValue("@age", age);
                  cmd.Parameters.AddWithValue("@dob", dob);
                  cmd.ExecuteNonQuery();


            } catch (Exception ex) {
                  throw ex;
            }


      }

}
BAL:
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public class insertbal
{
      insertdal obj = new insertdal();
      public void insertdetails(string name, int age, System.DateTime dob)
      {
            obj.insertdetails(name, age, dob);
      }
}
PL:


using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Data.SqlClient;
public class Form1
{
      insertbal OBJ = new insertbal();

      private void Button1_Click(System.Object sender, System.EventArgs e)
      {
            OBJ.insertdetails(TextBox1.Text, TextBox2.Text, DateTimePicker1.Value);

      }
}


No comments:

Post a Comment