Getting data in Datagridvw in buttnclick but unable 2 update

Posted by Kumartyr under DotNetFunda.Com on 5/15/2013 | Points: 10 | Views : 981 | Status : [Member] | Replies : 2
Getting data in Datagridview in a button click but unable 2 update
the changes that are done in the data in the gridview cells in the runtime and update the same & see the changes in the database as well as datagridview in runtime when i click the reload button

how to do that in C# language

am using microsoft data provider for .NET in oracle database




Responses

Posted by: Satyapriyanayak on: 5/15/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
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 Update_delete_datagridview
{
public partial class Form1 : Form
{
OleDbDataAdapter oledbda;
OleDbCommandBuilder olcb;
DataTable dataTable;
BindingSource bindingSource;
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
string str;

public Form1()
{
InitializeComponent();
}



private void btnaddupdate_Click(object sender, EventArgs e)
{
try
{
oledbda.Update(dataTable);
}
catch (Exception exceptionObj)
{
MessageBox.Show(exceptionObj.Message.ToString());
}
MessageBox.Show("Records updated");

}

private void btndelete_Click(object sender, EventArgs e)
{
try
{
dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);
oledbda.Update(dataTable);
}
catch (Exception exceptionObj)
{
MessageBox.Show(exceptionObj.Message.ToString());
}
MessageBox.Show("Records Deleted");
}

private void btn_showRecords_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "SELECT * FROM student";
oledbda = new OleDbDataAdapter(str, con);
olcb = new OleDbCommandBuilder(oledbda);
dataTable = new DataTable();
oledbda.Fill(dataTable);
con.Close();
bindingSource = new BindingSource();
bindingSource.DataSource = dataTable;
dataGridView1.DataSource = bindingSource;
dataGridView1.Columns[0].Visible = false;
}
}
}


If this post helps you mark it as answer
Thanks

Kumartyr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kumartyr on: 7/6/2013 [Member] Starter | Points: 25

Up
0
Down
Thanks for your reply

Kumartyr, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response