Tuesday, May 21, 2013

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        SqlDataSource1.Insert();
        GridView1.DataBind();
    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        SqlDataSource1.Delete();
        GridView1.DataBind();
    }
    protected void Button6_Click(object sender, EventArgs e)
    {
        SqlDataSource1.Update();
        GridView1.DataBind();
    }
}
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.SqlClient;

namespace Employee_Management
{
    public partial class Form1 : Form
    {

        SqlConnection con = new SqlConnection("Data Source=DELL;Initial Catalog=Company;User ID=sa;Password=m8002088");
        string[] deptarray = new string[] { "Development", "Support", "HR" };

        SqlCommand cmd;
        SqlDataReader dr;
        int id= 1;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.DataSource = deptarray;
            display();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            con.Open();
            cmd = new SqlCommand("select max(eid) from employee",con);
            int cnt = (int)cmd.ExecuteScalar();
            cnt = cnt + 1;
            textBox1.Text = Convert.ToString(cnt);

        }

        private void button3_Click(object sender, EventArgs e)
        {
            con.Open();
             cmd = new SqlCommand("select max(eid) from employee",con);
             int j = (int)cmd.ExecuteScalar();
             if (Convert.ToInt32(textBox1.Text) > j)
             {

                 cmd = new SqlCommand("insert into employee values(" + textBox1.Text + ",'" + textBox2.Text + "','" + comboBox1.SelectedItem.ToString() + "'," + textBox3.Text + ")", con);
                 int r = cmd.ExecuteNonQuery();
                 if (r > 0)
                     MessageBox.Show("Row Inserted!!!");
                 else
                     MessageBox.Show("Insert Data");
             }
             else
             {
                // cmd = new SqlCommand("insert into employee values(" + textBox1.Text + ",'" + textBox2.Text + "','" + comboBox1.SelectedItem.ToString() + "'," + textBox3.Text + ")", con);
                 cmd = new SqlCommand("update employee set ename='" + textBox2.Text + "',dep='" + comboBox1.SelectedItem.ToString() + "',age=" + textBox3.Text + " where eid=" + Convert.ToUInt32(textBox1.Text) + "", con);
               
                 int r = cmd.ExecuteNonQuery();
                 if (r > 0)
                     MessageBox.Show("Row udated!!!");
                 else
                     MessageBox.Show("Not updated");
             }
            con.Close();
            display();
        }
        public void display()
        {
            con.Open();
            cmd = new SqlCommand("select * from employee", con);
            dr = cmd.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Load(dr);
            dataGridView1.DataSource = dt;
            con.Close();
        }

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

        private void button5_Click(object sender, EventArgs e)
        {
           
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
     
           DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
           textBox1.Text = row.Cells[0].Value.ToString();

        }

        private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
        {

            DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
            textBox1.Text = row.Cells[0].Value.ToString();
        }
      

        private void button2_Click(object sender, EventArgs e)
        {

        }
    }
}
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.SqlClient;

namespace Employee_Management
{
    public partial class Form1 : Form
    {

        SqlConnection con = new SqlConnection("Data Source=DELL;Initial Catalog=Company;User ID=sa;Password=m8002088");
        string[] deptarray = new string[] { "Development", "Support", "HR" };

        SqlCommand cmd;
        SqlDataReader dr;
        int id= 1;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.DataSource = deptarray;
            display();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            con.Open();
            cmd = new SqlCommand("select max(eid) from employee",con);
            int cnt = (int)cmd.ExecuteScalar();
            cnt = cnt + 1;
            textBox1.Text = Convert.ToString(cnt);

        }

        private void button3_Click(object sender, EventArgs e)
        {
            con.Open();
             cmd = new SqlCommand("select max(eid) from employee",con);
             int j = (int)cmd.ExecuteScalar();
             if (Convert.ToInt32(textBox1.Text) > j)
             {

                 cmd = new SqlCommand("insert into employee values(" + textBox1.Text + ",'" + textBox2.Text + "','" + comboBox1.SelectedItem.ToString() + "'," + textBox3.Text + ")", con);
                 int r = cmd.ExecuteNonQuery();
                 if (r > 0)
                     MessageBox.Show("Row Inserted!!!");
                 else
                     MessageBox.Show("Insert Data");
             }
             else
             {
                // cmd = new SqlCommand("insert into employee values(" + textBox1.Text + ",'" + textBox2.Text + "','" + comboBox1.SelectedItem.ToString() + "'," + textBox3.Text + ")", con);
                 cmd = new SqlCommand("update employee set ename='" + textBox2.Text + "',dep='" + comboBox1.SelectedItem.ToString() + "',age=" + textBox3.Text + " where eid=" + Convert.ToUInt32(textBox1.Text) + "", con);
               
                 int r = cmd.ExecuteNonQuery();
                 if (r > 0)
                     MessageBox.Show("Row udated!!!");
                 else
                     MessageBox.Show("Not updated");
             }
            con.Close();
            display();
        }
        public void display()
        {
            con.Open();
            cmd = new SqlCommand("select * from employee", con);
            dr = cmd.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Load(dr);
            dataGridView1.DataSource = dt;
            con.Close();
        }

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

        private void button5_Click(object sender, EventArgs e)
        {
           
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
     
           DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
           textBox1.Text = row.Cells[0].Value.ToString();

        }

        private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
        {

            DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
            textBox1.Text = row.Cells[0].Value.ToString();
        }
      

        private void button2_Click(object sender, EventArgs e)
        {

        }
    }
}
private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
        {

            DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
            textBox1.Text = row.Cells[0].Value.ToString();

databinding

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.SqlClient;

namespace lab12_1
{
    public partial class Form1 : Form
    {
         SqlConnection con=new SqlConnection("Data Source=TANISH;Initial Catalog=department;User ID=sa;Password=seed");

         SqlDataAdapter da;
         DataSet ds = new DataSet();
       
        
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlDataAdapter sqlda = new SqlDataAdapter("insert into dept1 values("+textBox1.Text+",'"+textBox2.Text+"')", con);
            //da = new SqlDataAdapter("select * from dept1", con);
            //SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(sqlda);
         //   DataSet ds = new DataSet();

            sqlda.Fill(ds,"dept1");
           
            dataGridView1.DataSource = ds.Tables[0];
           
           
        }

        private void button5_Click(object sender, EventArgs e)
        {
            da = new SqlDataAdapter("select * from dept1", con);
            da.Fill(ds);
           // dataGridView1.Refresh();
            dataGridView1.DataSource = ds.Tables[0];
           
        }

        private void button3_Click(object sender, EventArgs e)
        {
            SqlDataAdapter sqlda = new SqlDataAdapter("Update dept1 set name='"+textBox2.Text+"' where id="+textBox1.Text+"", con);
            //da = new SqlDataAdapter("select * from dept1", con);
            //SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(sqlda);
            //   DataSet ds = new DataSet();

            sqlda.Fill(ds, "dept1");

            dataGridView1.DataSource = ds.Tables[0];
        }

        private void button4_Click(object sender, EventArgs e)
        {

            SqlDataAdapter sqlda = new SqlDataAdapter("delete from dept1 where id="+textBox1.Text+"" , con);
            //da = new SqlDataAdapter("select * from dept1", con);
            //SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(sqlda);
            //   DataSet ds = new DataSet();

            sqlda.Fill(ds, "dept1");

            dataGridView1.DataSource = ds.Tables[0];
        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            textBox1.DataBindings.Add("text", ds.Tables[0], "id");
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            textBox2.DataBindings.Add("text", ds.Tables[0], "name");
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            BindingContext[ds.Tables[0]].Position = ds.Tables[0].Rows.Count - 1;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (BindingContext[ds.Tables[0]].Position < ds.Tables[0].Rows.Count - 1)
                BindingContext[ds.Tables[0]].Position = BindingContext[ds.Tables[0]].Position + 1;
        }

        private void button6_Click(object sender, EventArgs e)
        {
             if(BindingContext[ds.Tables[0]].Position>0)
                BindingContext[ds.Tables[0]].Position=BindingContext[ds.Tables[0]].Position-1;

        }

        private void button8_Click(object sender, EventArgs e)
        {
            BindingContext[ds.Tables[0]].Position = 0;
        }
    }
}

Sunday, May 19, 2013

private void btnDeleteFL_Click(object sender, EventArgs e)

{

    if (MessageBox.Show("Are you sure you want to delete this feature?",

        "Confirm delete", MessageBoxButtons.YesNo) == DialogResult.Yes)

    {

        // Delete the require record according to the user command.              

    }
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.SqlClient;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        SqlConnection con = new SqlConnection("Data Source=ARNAV;Initial Catalog=Mrudu;User ID=sa;Password=manager");
        SqlCommand cmd;

        SqlDataReader dr;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            con.Open();
           
            cmd = new SqlCommand("insert into Cust values("+textBox1.Text+",'"+textBox2.Text+"')", con);
            int r=cmd.ExecuteNonQuery();
            if (r > 0)
                MessageBox.Show("Row Inserted!!!");
            else
                MessageBox.Show("Insert Data");
           
            con.Close();
            display();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            con.Open();
            cmd=new SqlCommand("delete from Cust where Cust_ID="+textBox1.Text);
            cmd.Connection = con;
            int r = cmd.ExecuteNonQuery();
            if (r > 0)
                MessageBox.Show("Row Deleted!!!");
            else
                MessageBox.Show("Not Deleted");
           
            con.Close();
            display();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            con.Open();
            cmd = new SqlCommand("update Employee set Emp_Name='"+textBox2.Text+"' where Emp_ID ="+textBox1.Text);
            cmd.Connection = con;
            int r = cmd.ExecuteNonQuery();
            if (r > 0)
                MessageBox.Show("Row updated");
            else
                MessageBox.Show("Not updated");
           
            con.Close();
            //display();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            con.Open();
            cmd = new SqlCommand("select count(Cust_ID) from Cust", con);
            int cnt = (int)cmd.ExecuteScalar();
            MessageBox.Show("Total No. of customers : "+cnt.ToString());
           
            con.Close();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            con.Open();
        
            cmd = new SqlCommand("StoredProcedure1", con);
            cmd.CommandType = CommandType.StoredProcedure;

            SqlParameter param = new SqlParameter();
            param.ParameterName = "@cno";
            param.Value = textBox1.Text;
            cmd.Parameters.Add(param);

            dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                MessageBox.Show("ID : " + dr[0].ToString());
                MessageBox.Show("Name : " + dr[1].ToString());
            }
           
            con.Close();
            //display();
        }
        public void display()
        {
            con.Open();
            cmd = new SqlCommand("select * from Cust", con);
            dr = cmd.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Load(dr);
            dataGridView1.DataSource = dt;
            con.Close();

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            display();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

      

       
    }
}