Monday, August 16, 2010

Example C# code for Asp.net datagrid view with bound textbox fields and read into MS SQL DB?

I am programming a datagrid that pulls bound data from a DB based on the user selection. There are 5 columns no matter what.


The idea is to have an excel type input and the upon hitting the save changes button all the data gets feed into the database.


Everything works except the save button. I am currently running a loop where It runs for the number of rows in the grid, pulls the data from each field as a textbox, converts the data to the appropriate datatype and puts it into a dataset, but once I get that far I can't get the save function to work properly. So basically where I am at is I have a dataset, with information from the grid and I need to put it into a MS SQL server.





I am looking for a basic example of how my code should look from here.Example C# code for Asp.net datagrid view with bound textbox fields and read into MS SQL DB?
1. Bind your DataGrid via a DataAdapter that fills the DataSet.





2. Make changes to your DataSet.





3. Use this code to update to SQL:





SqlCommandBuilder myBuilder = new SqlCommandBuilder( myDataAdapter );


myDataAdapter.Update( myDataSet, ';TableName';);Example C# code for Asp.net datagrid view with bound textbox fields and read into MS SQL DB?
Hard to tell from your example what is going on in code. They have some good datagrid examples here.





http://www.asp.net/get-started/





Are you using visual studio? They have a free visual designer at this site that is really easy to use. I program in VS everyday so list your code if you need more help.





cheers

No comments:

Post a Comment