Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C# BindingNavigator Control

Posted on 2006-07-19
4
Medium Priority
?
3,492 Views
Last Modified: 2012-08-14
I have populated DateGridView control with following code:

DataTable dataTable = new DataTable();
SqlDataAdapter da = new SqlDataAdapter("select * from Customers", someConnectionString);
dataTable.Clear();
da.Fill(dataTable);
dataGridView1.DataSource = dataTable;

Now I would like to add BindingNavigator Control so that user can easily navigate, add or remove records.
How do I "linked" the two controls?
0
Comment
Question by:michellechan57
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
e1v earned 2000 total points
ID: 17142028
If you have a BindingNavigator called bindingNavigator1 on your form, you can to this:

DataTable dataTable = new DataTable();
SqlDataAdapter da = new SqlDataAdapter("select * from Customers", someConnectionString);
dataTable.Clear();
da.Fill(dataTable);

BindingSource bindingSource = new BindingSource(dataTable, null);
dataGridView1.DataSource = bindingSource;
bindingNavigator1.BindingSource = bindingSource;


0
 

Author Comment

by:michellechan57
ID: 17142381
Hi e1v,

It works. Thanks. May I ask why the add and delete buttons in the BindingNavigator did not update the table when pressed (or should I ask as a new question)?
0
 
LVL 6

Expert Comment

by:e1v
ID: 17144222
Hi,  with "did not update the table " did you mean that dhe database did not get updated? To that you must explisit do a update and for that you need update, delete and insert-commands in your SqlDataAdapter.
Those can you create using SqlCommandBuilder like:

 SqlCommandBuilder sb = new SqlCommandBuilder(da);
            da.UpdateCommand = sb.GetUpdateCommand();
            da.DeleteCommand = sb.GetDeleteCommand();
            da.InsertCommand = sb.GetInsertCommand();

and then do
da.Update(dataTable); to write changes to the database.

All this you get for free when using drag-and-drop databinding with datasets, so for simple projects it might be worth looking into.
0
 

Author Comment

by:michellechan57
ID: 17146779
Thanks.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question