简体   繁体   中英

Using SQL Server Database View for populating DataGridView and modifying data in DB

I want to know that how this will be done and if this is not a good solution, then please elaborate if any other good solution is possible .


1) Initially I want to use a Database View for populating different DataGridViews .

2) Multiple joins from multiple tables are required for the data-retrieval for each individual DataGridView .

3) The values from these DataGridViews are then populated in Controls (ie Textboxes/Combo-boxes) (For reference please see the images at this link: link text ).

4) When the User changes the values in Controls , and clicks Save , the data earlier retrieved from DataGridView (via View ) is to be updated in the Database .


NOTE:I am working on C-Sharp Windows Application and using SQL Server 2005.

1) I'm not sure how you can bind a control directly to a View, but you can edit your DataSet (assuming your using the designer under data sources right click on your dataset and click "edit dataset in designer", once there you can right click and add a table adapter which you can populate however you want (For example

   SELECT * FROM [YourView] 

Alternatively you could just use a stored procedure or type the SQL there to populate the Table Adapter.

Once you have added a table adapter to your dataset you can bind your DataGrid to that table adapter just as you would to a regular table.

I know this is probably now what your looking for but the truth is that I came across your question while looking for a way to do more or less the same thing.

2) You table adapter can be based on many tables using either a SQL statement or a Stored Procedure.

3) Why don't you directly bind those controls using their datasource property?

4) If the controls are themselves bound then you can change the data through the controls and to see the changes in your datagrid you should just need to "refresh" (call it's databind() method) to see the updated data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM