Datagrid to Database

knockyo

Well-known member
Joined
Sep 20, 2006
Messages
78
Programming Experience
1-3
How to store/insert all the data in the datagrid into SQL server database?

no matter how many column or row inside the datagrid, direct save into the database by one SAVE button?

better have some coding and show me ;p

Thanks,
 
Forget about the DataGrid. A DataGrid is for display purposes and has nothing to do with saving data to a database. You retrieve data from a database into a DataTable using a DataAdapter and its Fill method. You can then do whatever you like with that DataTable, including bind it to a DataGrid or other controls. The user can then edit the data to their heart's content. You then save any changes made in the DataTable using the same DataAdapter and its Update method. The DataAdapter doesn't care where the changes came from, so the DataGrid is irrelevant to the process of saving the data.

I suggest that you do some reading on ADO.NET, which is the standard .NET data access technology. Fellow member TechGnome has a link to his own tutorials in his signature. The tutorial links in my signature will also shed some light on the topic, as will many other tutorials on the Web.
 
u means that i totally can't save any records from datagrid?

i only can retrieve and display purpose?

do u hv any idea how to update/save all the datagrid data that i have been edited?
 
I didn't say that you cannot save data that is displayed in the DataGrid. I said that the DataGrid has nothing to do with the saving process.

Let's say that you go to a bank and withdraw some money. You can then go and spend your money, invest it or whatever. You can then go back to the bank and deposit what you have left from change or what you've earned. The bank teller doesn't care where the money came from, only that it is money.


The same is true of your data. It is the DataAdapter that interacts with the database to retrieve and save the data. The data is stored in a DataTable. That's all that matters as far as data access is concerned. You can certainly display that data in a DataGrid and you make changes in that grid. You can then save the changes that were made back to the database, but the fact that they were made in a DataGrid is irrelevant to the data access process.

I pointed you to several tutorials in my signature and fellow member TechGnome's. There are plenty of code examples in those tutorials, so I'm not going to repeat them here.
 
Back
Top