Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
How do I update a modified row of my datagridview to the db?
i had tried a lot...
but nothing happened....
 
i asked this question 2 days before....
can any one help me....
 
tried following code: but...
private void showButton_Click(object sender, EventArgs e)
{
con =  new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\ETMS\\ETMS\\ETMS\\etms.accdb");
String query = "SELECT * FROM Categories";
da = new OleDbDataAdapter(query, con);
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
con.Close();
}
private void UpdateButton_Click(object sender, EventArgs e)
{
da.Update(ds);
}
if i run the code
i am getting the following error
"update requires a valid update command when pressed datarow collection with modified rows"
Please help me...
thank you
Posted 13-Jun-11 1:03am
Ragi Gopi1.3K
Edited 13-Jun-11 6:03am
thatraja230K
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

you can do this way:
 
private void showButton_Click(object sender, EventArgs e)
{
con =  new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\ETMS\\ETMS\\ETMS\\etms.accdb");
String query = "SELECT * FROM Categories";
da = new OleDbDataAdapter(query, con);
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
dt=new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
}
private void UpdateButton_Click(object sender, EventArgs e)
{
da.Update(dt);
}
 
for further info refer to following links:
 
Edit Almost Anything in a DataGrid[^]
 
Auto Saving DataGridView Rows to a SQL Server Database[^]
 
hope this helps Smile | :)
 
[Edit] by Tadit
Corrected the second link's html.
As it was showing the whole html where new window icon is shown.
[/Edit]
  Permalink  
v3
Comments
Ragigopi at 14-Jun-11 2:45am
   
@Uday P.Singh Thanku buddy.... Its Works.......
Uday P.Singh at 14-Jun-11 2:52am
   
welcome :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

This may help you.,
private void showButton_Click(object sender, EventArgs e)
{
    con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\ETMS\\ETMS\\ETMS\\etms.accdb");
    String query = "SELECT * FROM Categories";
    da = new OleDbDataAdapter(query, con); 
    OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
    ds = new DataSet();
    da.Fill(ds);
    dataGridView1.DataSource = ds.Tables[0];
    con.Close();
}
private void UpdateButton_Click(object sender, EventArgs e)
{
    DataSet ds1 = ((DataSet)dataGridView1.DataSource).GetChanges();
    da.Update(ds1);
}
  Permalink  
Comments
codesharper at 13-Jun-11 8:15am
   
This is better idia to affect only changes into database but you must create insert and update command to affect the record in database.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This link might be of some help.
  Permalink  
Comments
Ragigopi at 13-Jun-11 7:35am
   
following error is displayed.... "update requires a valid update command when pressed datarow collection with modified rows"
Ragigopi at 13-Jun-11 7:36am
   
@RakeshMeena i tried ur linq but again the same error is generated...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hope this[^] will help you..
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

please check you table and put a primary key if you don't have.
and if the error is still persist try to use the solution of Uday P.Singh Smile | :)
Happy Coding!!!!
  Permalink  
Comments
Ragigopi at 14-Jun-11 2:46am
   
@Joemar Valete i tried solution of Uday P.Singh.. its works :)
Joemar Valete at 14-Jun-11 2:51am
   
Good for you :)

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 412
1 sanket saxena 355
2 Abhinav S 258
3 OriginalGriff 210
4 CPallini 205
0 Sergey Alexandrovich Kryukov 8,704
1 OriginalGriff 5,000
2 Peter Leow 3,839
3 Maciej Los 3,535
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid