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 WindowsFormsApplication7 { public partial class Form1 : Form { string strCon = "Data Source=CIODEV03\\SQLEXPRESS;Initial Catalog=EmployeeDB;Integrated Security=True"; string strSQL; SqlConnection conn; SqlCommand cmd; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { string strSQL = "select * from gridview"; SqlDataAdapter dataAdapter = new SqlDataAdapter(strSQL, strCon); SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter); DataTable table = new DataTable(); table.Locale = System.Globalization.CultureInfo.InvariantCulture; dataAdapter.Fill(table); bindingSource1.DataSource = table; dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader); dataGridView1.ReadOnly = true; dataGridView1.DataSource = bindingSource1; } private void btninsert_Click(object sender, EventArgs e) { strSQL = "insert into gridview values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')"; conn = new SqlConnection(strCon); cmd = new SqlCommand(strSQL, conn); conn.Open(); cmd.ExecuteNonQuery(); dataGridView1.DataSource = bindingSource1; conn.Close(); } private void btnupdate_Click(object sender, EventArgs e) { strSQL = "update gridview set ID='" + textBox1.Text + "',Name='" + textBox2.Text + "',Address='" + textBox3.Text + "'"; conn = new SqlConnection(strCon); cmd = new SqlCommand(strSQL, conn); conn.Open(); cmd.ExecuteNonQuery(); dataGridView1.DataSource = bindingSource1; } private void btndelete_Click(object sender, EventArgs e) { strSQL = "delete from gridview"; conn = new SqlConnection(strCon); cmd = new SqlCommand(strSQL, conn); conn.Open(); cmd.ExecuteNonQuery(); dataGridView1.DataSource = bindingSource1; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)