Click here to Skip to main content
15,905,971 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually i am created one table in ms access.This table can view through the datagridview.now i am any changes on the gridview that automatically change to the database how is it? pls help me.

i.e) edit and delete on the datagridview that automatically changes to the database.
Posted

 
Share this answer
 
check the following codeproject article

Add, Edit, and Delete in DataGridView with Paging[^]
 
Share this answer
 
 
Share this answer
 
//for(int i=0;i<dataGridView1 .Rows .Count -1;i++)
// {
// string a =dataGridView1.Rows[i].Cells["c_name"].Value.ToString();
// string b = dataGridView1.Rows[i].Cells["o_no"].Value.ToString();
// string c = dataGridView1.Rows[i].Cells["date"].Value.ToString();
//string d = dataGridView1.Rows[i].Cells["kgs"].Value.ToString();
//string x = dataGridView1.Rows[i].Cells["count"].Value.ToString();
string query = "UPDATE tablename SET c_name='" + a + "',o_no='" + b + "',date='" + c + "',kgs='" + d + "',count=" + x + " where yarntable.c_name='" + a + "' and yarntable.o_no='" + b + "'";
//OleDbConnection con = new OleDbConnection("databasepath");
// con.Open();
// OleDbCommand cmd = new OleDbCommand(query, con);
// cmd.ExecuteNonQuery();
// con.Close();
// }
//MessageBox.Show("successfully edited on database");
 
Share this answer
 
You can Use AutoGenerate Properties to enable user to edit row, and delete row..
And GridView Provides Several Events like
1)OnRowEdit
2)OnRowEdited
3)OnRowSelected
4)OnRowDeleting
5)OnRowDeleted

etc..
And make use of these events, if you want to make any changes while editing deleting.

ASP.NET
<asp:gridview autogenerateeditbutton="True" autogeneratedeletebutton="True" xmlns:asp="#unknown">
            runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" 
            onrowediting="My_RowEditing" onrowupdated="My_RowUpdated"  >
        <columns>
            <asp:boundfield datafield="gender" headertext="gender">
                SortExpression="gender" />
        </asp:boundfield></columns>
        </asp:gridview>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900