Você está na página 1de 12

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 ADO
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection con;
DataSet ds;
SqlDataAdapter da;
SqlCommand cmd;
DataView dv;
CurrencyManager cur;
public void DataBind()
{

con = new SqlConnection(@"Data Source=PROG77PC\SQLEXPRESS;Initial Catalog=test;Integrated Security=True");


ds = new DataSet();
da = new SqlDataAdapter("select * from Employee",con);
con.Open();
da.Fill(ds,"emp");
con.Close();
dv = new DataView(ds.Tables["emp"]);
cur = (CurrencyManager)(BindingContext[dv]);
textBox1.DataBindings.Clear();
textBox1.DataBindings.Add("Text", dv, "First_Name");
textBox2.DataBindings.Clear();
textBox2.DataBindings.Add("Text", dv, "Last_Name");
textBox3.DataBindings.Clear();
textBox3.DataBindings.Add("Text", dv, "Email_ID");
textBox4.DataBindings.Clear();
textBox4.DataBindings.Add("Text", dv, "Contact");
dataGridView1.DataSource = dv;
lblposition.Text = (cur.Position + 1) + " of " +

cur.Count;
}
private void Form1_Load(object sender, EventArgs e)
{
DataBind();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
}
private void button4_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
btnSave.Enabled = true;
}
private void button5_Click(object sender, EventArgs e)
{
con = new SqlConnection(@"Data Source=PROG77PC\SQLEXPRESS;Initial Catalog=test;Integrated Security=True");
cmd = new SqlCommand("insert into Employee
values(@f,@l,@email ,@cont)",con);

cmd.Parameters.AddWithValue("@f", textBox1.Text);
cmd.Parameters.AddWithValue("@l", textBox2.Text);
cmd.Parameters.AddWithValue("@email", textBox3.Text);
cmd.Parameters.AddWithValue("@cont", textBox4.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
DataBind();
MessageBox.Show("Employee Data inserted Successfully");

private void button3_Click(object sender, EventArgs e)


{
string update = "update Employee set
Last_Name=@l,Email_ID=@e,Contact=@cont where First_Name=@f";
cmd = new SqlCommand(update,con);
cmd.Parameters.AddWithValue("@f", textBox1.Text);
cmd.Parameters.AddWithValue("@l", textBox2.Text);
cmd.Parameters.AddWithValue("@e", textBox3.Text);
cmd.Parameters.AddWithValue("@cont", textBox4.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
DataBind();
MessageBox.Show("Employee Data updated Successfully");
}
private void btnfirst_Click(object sender, EventArgs e)
{
cur.Position = 0;
lblposition.Text = (cur.Position + 1) + " of " +
cur.Count;
}
private void btnPrev_Click(object sender, EventArgs e)
{
cur.Position--;
lblposition.Text = (cur.Position + 1) + " of " +
cur.Count;
}
private void btnNext_Click(object sender, EventArgs e)
{
cur.Position++;
lblposition.Text = (cur.Position + 1) + " of " +
cur.Count;
}
private void btnLast_Click(object sender, EventArgs e)
{
cur.Position = cur.Count - 1;

cur.Count;
}

lblposition.Text = (cur.Position + 1) + " of " +

private void btnDelete_Click(object sender, EventArgs e)


{
string update = "Delete from Employee where
First_Name=@f";
cmd = new SqlCommand(update, con);
cmd.Parameters.AddWithValue("@f", textBox1.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
DataBind();
MessageBox.Show("Data Deleted Successfully");
}
private void btnSearch_Click(object sender, EventArgs e)
{
//To search data
con = new SqlConnection(@"Data Source=PROG77PC\SQLEXPRESS;Initial Catalog=test;Integrated Security=True");
string search = "select * from Employee where First_Name
like '"+textBox5.Text+"%'";
cmd = new SqlCommand(search,con);
da = new SqlDataAdapter(cmd);
con.Open();
da.Fill(ds,"emp");
con.Close();
dv = new DataView(ds.Tables["emp"]);
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
}
}

using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;

namespace ADO
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
SqlConnection con;
DataSet ds;
SqlDataAdapter da;
SqlCommand cmd;
DataView dv;
CurrencyManager cur;
private void btnSearch_Click(object sender, EventArgs e)
{
con = new SqlConnection(@"Data Source=PROG77PC\SQLEXPRESS;Initial Catalog=test;Integrated Security=True");
string search = "select * from Employee where First_Name
like '" + textBox5.Text + "%'";
da = new SqlDataAdapter(search, con);
ds = new DataSet();
con.Open();
da.Fill(ds, "emp");
con.Close();
dataGridView1.DataSource = ds.Tables["emp"];
}
}
}

using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;

namespace ADO
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
SqlConnection con;
DataSet ds;
SqlDataAdapter da;
SqlCommand cmd;
DataView dv;
CurrencyManager cur;
private void btnSearch_Click(object sender, EventArgs e)
{
con = new SqlConnection(@"Data Source=PROG77PC\SQLEXPRESS;Initial Catalog=test;Integrated Security=True");
string search = "select * from Employee where First_Name
like '" + textBox5.Text + "%'";
da = new SqlDataAdapter(search, con);

ds = new DataSet();
con.Open();
da.Fill(ds, "emp");
con.Close();
dataGridView1.DataSource = ds.Tables["emp"];
dv = new DataView(ds.Tables["emp"]);
cur = (CurrencyManager)(BindingContext[dv]);
textBox5.DataBindings.Clear();
textBox5.DataBindings.Add("Text", dv, "First_Name");
textBox2.DataBindings.Clear();
textBox2.DataBindings.Add("Text", dv, "Last_Name");
textBox3.DataBindings.Clear();
textBox3.DataBindings.Add("Text", dv, "Email_ID");
textBox4.DataBindings.Clear();
textBox4.DataBindings.Add("Text", dv, "Contact");
dataGridView1.DataSource = dv;
}
}

using
using
using
using
using
using
using
using
using
using

System;
System.Collections;
System.Configuration;
System.Data;
System.Linq;
System.Web;
System.Web.Security;
System.Web.UI;
System.Web.UI.HtmlControls;
System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace WebApplication3
{
public partial class _Default :
System.Web.UI.Page
{
public SqlConnection con;
public string constr;
public void connection()
{
constr =
ConfigurationManager.ConnectionStrings["emp"].To
String();
con = new SqlConnection(constr);
con.Open();
}
protected void Page_Load(object sender,
EventArgs e)
{

Label1.Visible = false;
data_bind();

private void data_bind()


{
connection();
string query = "select * from
Employee where First_Name like'" + TextBox1.Text
+ "%'";

SqlDataAdapter da = new
SqlDataAdapter(query, con);
DataSet ds = new DataSet();
da.Fill(ds);
//GridView1.DataSource = ds;
//GridView1.DataBind();
}
protected void Button1_Click(object
sender, EventArgs e)
{
connection();
string query = "select First_Name
from Employee where First_Name like'" +
TextBox1.Text + "%'";
SqlCommand com = new
SqlCommand(query, con);
SqlDataReader dr;
dr = com.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
data_bind();
GridView1.Visible = true;
TextBox1.Text = "";
Label1.Text = "";
}
else
{

GridView1.Visible = false;
Label1.Visible = true;
Label1.Text = "The search Term "
+ TextBox1.Text + " ;Is Not Available in the
Records"; ;
}
}
}

Você também pode gostar