c#, using a datagridview bound

I have used the datagridview control for years, but always unbound.  For the first time I set a datasource and don't fully understand what happened.  I see the DataSource for the grid is now "blahblahBindingSource".  Unfortunately, I don't know how to use it.

Is there a dataset associated with this?  When the user changes something in the grid, do I then need to update the dataset to commit changes to the database?

I am using .Net 4.5 if that makes any difference.  I am connected to a SQL Server database.

Any help would be greatly appreciated.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hello g_johnson,  
it appears you are now doing things the easy way, by setting the datasource from the markup page rather than the behind code.  

You generally do not need any code behind (ie C#) to support this method of binding. Just a data source eg SQLDataSource (if using MSSQL), which allows you to reference the table or view that you need to display.  It allows you to construct the query or display the table by simply selecting the fields you require.

In your datagrid you then bind it to that data source using the smart tags.  This is easy to do.  It may then create some code on the markup page which helps to display the fields based on their type, eg int, text etc.  It is then very easy to make changes to your displayed grid, like change displayed field names atc.

This is generally easier to do and is great for testing and mock-ups but can lead to some security risks if people view the source code of the page, and may see the connection string and data binding information, eg field names etc.

hope this clears things up 4 u

here is a sample in action

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Rulesdb2]"></asp:SqlDataSource>
        <br />
        Sample Grid Here<br />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Rulesdb2ID" DataSourceID="SqlDataSource1" EnableModelValidation="True">
                <asp:BoundField DataField="Rulesdb2ID" HeaderText="Rulesdb2ID" ReadOnly="True" SortExpression="Rulesdb2ID" />
                <asp:BoundField DataField="Rulesdb2Text" HeaderText="Rulesdb2Text" SortExpression="Rulesdb2Text" />

Open in new window

g_johnsonAuthor Commented:
This is a Windows Form application, the source code will not be visible to the user so that's good -- no security issues.  However, when the user changes something in the grid, how does that get committed to the database?

g_johnsonAuthor Commented:
I found the answer to the question.  You choose the appropriate variation of the dataAdapter.Update method, such as:


Thanks for your input.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
if you plan to make an web application the code above will work fine also.
g_johnsonAuthor Commented:
This answers the question directly and completely.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.