Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have coded my own as the following:
After loading a table in the sql database into dataTable1:

C#
textBox1.DataBindings.Add("Text", dataTable1, "Name");


After editing something in the textBox1, I checked the value of the cell at the first row of the column "Name", it had changed to the Text of textBox1. (the first row because that's the current row after loading the dataTable1). Then I started updating:

C#
sqlAdapter1.Update(dataTable1);


I think it should work, but the data can't be updated. If I change the value of the cell at the first row of the column "Name" like as
C#
dataTable1.Rows[0]["Name"] = "Chan doi VL"
, it works perfectly.

Could you please help me out? I really don't want to use UPDATE statement.
Thank you so much!
Posted
Updated 13-Sep-11 2:42am
v3
Comments
Herman<T>.Instance 13-Sep-11 6:37am    
updating values in a database without using update statement? good luck my friend!
(Why not use an update statement?)
Pravin Patil, Mumbai 13-Sep-11 7:00am    
But what is wrong in using the UPDATE statement....?
[no name] 13-Sep-11 8:18am    
UPDATE in particular and other SQL statements in general are basis and I think they are the core behind other classes manipulating on database like DataAdapter.
You use adapter as well as you use UPDATE indirectly, and in some cases, using dataadapter is better.
Thank you!

What happen if you invoke AcceptChanges on your data table? Did you try it?
 
Share this answer
 
Comments
Simon Bang Terkildsen 13-Sep-11 6:34am    
AcceptChanges will not help, on the contrary, as the rows will enter the Unchanged state and thus nothing will be committed to the database.
CodingLover 13-Sep-11 6:47am    
Yes, but the OP is talking about committing to the database I guess. Isn't it?
Simon Bang Terkildsen 13-Sep-11 10:41am    
No it doesn't have anything to do with commiting to the database except to make sure that the current changes will NOT be commited. see
DataTable.AcceptChanges
DataSet.AcceptChanges
[no name] 13-Sep-11 8:05am    
I have tried adding AcceptChanges but it didn't work.

I think editing the textbox can't change the corresponding value in the datatable, but I can't understand that after editing the textbox, I checked the corresponding value in the datatable and it was exactly equal to the Text property of the textbox! As you can see in my question, I tried assigning a value to the first cell of the datatable directly and the update method worked well!
Can't understand what it is?
Thank you!
You can't do it without using the update statement.
 
Share this answer
 
Comments
[no name] 14-Sep-11 23:10pm    
So why I can do with using a datagridview or assigning some value directly to a specified cell of the datatable and just simply call update method of the dataadapter? Can't do the same with a textbox?
Thank you so much!
#realJSOP 15-Sep-11 4:48am    
If you could get to the underlying code, you'll find that it is in fact using an update statement to update the database. Ergo, you CANNOT update the database without the update statement.
[no name] 15-Sep-11 15:33pm    
I'm sorry, I mean that update the database without using update statement directly and manually. I really like the automatic update by the dataadapter and commandbuilder.
Is that now clear?
Thank you so much!

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