CRUD Operations using DataGridView || Simple C# Code & Project || Insert Update Delete Read



#CRUD Operations using DataGridView || Simple C# Code & Project || Insert Update Delete Read

DataTable table = new DataTable();
private void Form1_Load(object sender, EventArgs e)
{
table.Columns.Add(“Id”, typeof(int));
table.Columns.Add(“Name”, typeof(string));
table.Columns.Add(“Department”, typeof(string));
dataGridView1.DataSource = table;

}

private void button3_Click(object sender, EventArgs e)
{
table.Rows.Add(textBox1.Text, textBox2.Text, textBox3.Text);
dataGridView1.DataSource = table;
}
int id = 0;
private void button2_Click(object sender, EventArgs e)
{
dataGridView1.Rows[id].Cells[0].Value = textBox1.Text;
dataGridView1.Rows[id].Cells[1].Value = textBox2.Text;
dataGridView1.Rows[id].Cells[2].Value = textBox3.Text;
}

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
id = e.RowIndex;
textBox1.Text = dataGridView1.Rows[id].Cells[0].Value.ToString();
textBox2.Text = dataGridView1.Rows[id].Cells[1].Value.ToString();
textBox3.Text= dataGridView1.Rows[id].Cells[2].Value.ToString();
}

private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = “”;
textBox2.Text = “”;
textBox3.Text = “”;
}

private void button4_Click(object sender, EventArgs e)
{
dataGridView1.Rows.RemoveAt(id);
} DataTable table = new DataTable();
private void Form1_Load(object sender, EventArgs e)
{
table.Columns.Add(“Id”, typeof(int));
table.Columns.Add(“Name”, typeof(string));
table.Columns.Add(“Department”, typeof(string));
dataGridView1.DataSource = table;

}

private void button3_Click(object sender, EventArgs e)
{
table.Rows.Add(textBox1.Text, textBox2.Text, textBox3.Text);
dataGridView1.DataSource = table;
}
int id = 0;
private void button2_Click(object sender, EventArgs e)
{
dataGridView1.Rows[id].Cells[0].Value = textBox1.Text;
dataGridView1.Rows[id].Cells[1].Value = textBox2.Text;
dataGridView1.Rows[id].Cells[2].Value = textBox3.Text;
}

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
id = e.RowIndex;
textBox1.Text = dataGridView1.Rows[id].Cells[0].Value.ToString();
textBox2.Text = dataGridView1.Rows[id].Cells[1].Value.ToString();
textBox3.Text= dataGridView1.Rows[id].Cells[2].Value.ToString();
}

private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = “”;
textBox2.Text = “”;
textBox3.Text = “”;
}

private void button4_Click(object sender, EventArgs e)
{
dataGridView1.Rows.RemoveAt(id);
}