Hi All,
Please help me to solve this problem
i have a table named TabDetails containing columns id,FirstName,LastName.
There is a DataGridView and i have set the data source of the DataGridView to be TadDetails.
Now the DataGridView contains columns id,FirstName,LastName.
There is also a button named Save.
When i click the save button i need the details in the DataGridView to be saved in the table TabDetails.
How can we do it using the insert statements.?
or is there any other way to implement the above.
could me please tell the source code for the above
Thank You,
Satyapriya NayakPosted Jun 14, 2014, 12:05 AM
http://ahmadkhalid44.blogspot.in/2013/04/how-to-insert-update-select-and-delete.html
Mohammad IshaqPosted Jun 13, 2014, 2:25 PM
Satyapriya NayakPosted Jun 13, 2014, 1:26 PM
Mohammad IshaqPosted Jun 13, 2014, 12:45 PM
I am not sure but i think the code you given me is for c# . and i required the code for vb.net.
My project is in VB.I have write the code for connection to datagridview .Now i required only the code for Edit,Delete,Update,New Entry,First,Last,Refresh,Next buttons.
Please let me guide about this.The code is given below.
Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\EmplTable.accdb;")
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM EmpData", con)
con.Open()
Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "EmpData")
DataGridView1.DataSource = myDataSet.Tables("EmpData").DefaultView
con.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
End Class
Satyapriya NayakPosted Jun 12, 2014, 11:11 PM
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 Form1_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "SELECT * FROM TabDetails";
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;
}
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");
}
}
}