how to insert,update,delete using data grid view in database in windows application

Posted by suri1319-13143 under C# on 12/28/2011 | Points: 10 | Views : 12376 | Status : [Member] | Replies : 6
how to insert update, delete using data grid view in database in windows application please help me..... my mail me suri1319@gmail.com




Responses

Posted by: SheoNarayan on: 12/28/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Hi Suri....

Read these articles to achieve what you want

http://www.dotnetfunda.com/articles/article180.aspx*
http://www.dotnetfunda.com/articles/article29.aspx
http://www.dotnetfunda.com/articles/article924-add-edit-delete-paging-records-in-gridview-using-jquery.aspx

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

suri1319-13143, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: suri1319-13143 on: 12/28/2011 [Member] Starter | Points: 25

Up
0
Down
thank you SheoNarayan thank you very much....!

suri1319-13143, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: suri1319-13143 on: 12/29/2011 [Member] Starter | Points: 25

Up
0
Down
Hi SheoNaran.....
thank you for your proper response those links are very use full in my carrier.
in windows how to work with grid view as insert, update, delete buttons please help me
send me code to suri1319@gmail.com

suri1319-13143, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 12/29/2011 [Member] Starter | Points: 25

Up
0
Down
hi
Read this article
http://www.codeproject.com/KB/aspnet/InsertingWithGridView.aspx

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

suri1319-13143, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Aditya1234567 on: 3/2/2013 [Member] Starter | Points: 25

Up
0
Down
can any1 tell me about insert,update and delete in database in easy way as i m starter so easy to understand for me.

suri1319-13143, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 3/2/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Form1.cs

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.OleDb;
namespace Insert_Update_Delete_DataGridView
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oledbda;
string str;
DataSet ds;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
bindgrid();
}
private void bindgrid()
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from employee";
com = new OleDbCommand(str, con);
oledbda = new OleDbDataAdapter(com);
ds = new DataSet();
oledbda.Fill(ds, "employee");
dataGridView1.DataMember="employee";
dataGridView1.DataSource = ds;
con.Close();
}
private void Clear()
{
txt_sno.Text = "";
txt_name.Text = "";
txt_address.Text = "";
txt_age.Text = "";
}

private void btn_edit_Click(object sender, EventArgs e)
{
int i;
i = dataGridView1.SelectedCells[0].RowIndex;
txt_sno.Text = dataGridView1.Rows[i].Cells[1].Value.ToString();
txt_name.Text = dataGridView1.Rows[i].Cells[2].Value.ToString();
txt_address.Text = dataGridView1.Rows[i].Cells[3].Value.ToString();
txt_age.Text = dataGridView1.Rows[i].Cells[4].Value.ToString();
}

private void btn_update_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "Update employee set sno=@sno,name=@name,address=@address,age=@age Where sno=@sno";
com = new OleDbCommand(str, con);
com.Parameters.AddWithValue("@sno", txt_sno.Text);
com.Parameters.AddWithValue("@name", txt_name.Text);
com.Parameters.AddWithValue("@address", txt_address.Text);
com.Parameters.AddWithValue("@age", txt_age.Text);
com.ExecuteNonQuery();
MessageBox.Show("Record Successfully Updated");
con.Close();
bindgrid();
Clear();
}

private void btn_delete_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
com = new OleDbCommand();
if (dataGridView1.Rows.Count > 1 && dataGridView1.SelectedRows[0].Index != dataGridView1.Rows.Count - 1)
{
com.CommandText = "DELETE FROM employee WHERE ID=" + dataGridView1.SelectedRows[0].Cells[0].Value.ToString() + "";
con.Open();
com.Connection = con;
com.ExecuteNonQuery();
con.Close();
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
MessageBox.Show("Record Successfully Deleted");
}
bindgrid();
}

private void btn_insert_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "Insert into employee(sno,name,address,age) Values (@sno,@name,@address,@age)";
com = new OleDbCommand(str, con);
com.Parameters.AddWithValue("@sno", txt_sno.Text);
com.Parameters.AddWithValue("@name", txt_name.Text);
com.Parameters.AddWithValue("@address", txt_address.Text);
com.Parameters.AddWithValue("@age", txt_age.Text);
com.ExecuteNonQuery();
con.Close();
MessageBox.Show("Record Successfully Inserted");
bindgrid();
Clear();
}
}
}



If this post helps you mark it as answer
Thanks

suri1319-13143, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response