Dataset from datasource returns no rows

K

kwele

I set up a dataset from Add New Data Source ... on the Data Sources
tab. I selected two tables with a parent/child relationship.

The wizard created the .xsd file. I then dragged the parent datasource
over to the forms designer, where it created a bindingsource,
bindingnavigator and GridView.

This is the first time I've tried creating a dataset this way. Somehow
I assumed that it was doing all the coding, like creating the
dataadapter and filling the dataset.

When I ran the app, the counter on the bindingnavigator says "0 of 0".
I know there are 5 rows in the parent and 1 in the child.

What am I missing here?

TIA Kwele
 
W

WenYuan Wang

Hi Kwele,
Thanks for your post.

According to your description, I understand that the bindingnavigator
control can not get records from database after you have dropped a
datasource to form designer.
If I misunderstand anything here, please don't hesitate to correct me.

Under my research, I find there is a tutorial about how to use
bindingnavigator control on MSDN website. Would you mind testing these
steps as this document mentioned to check whether or not it works for you?
http://msdn.microsoft.com/vstudio/tour/vs2005_guided_tour/vs2005pro/smart_cl
ient/BindingNavigator.htm
[Windows Forms - BindingNavigator]

By the way, as you have known, VS will do all the coding for us (such as
creating the dataadapter and filling the dataset) after we drop the
datasource to form designer.
For example:
private void Form2_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the
'testDataBase20060908DataSet.Terms' table. You can move, or remove it, as
needed.

this.termsTableAdapter.Fill(this.testDataBase20060908DataSet.Terms);
}

We suggest you can open .cs file to check whether VS has added all these
codes for you when you drop the datasource to form.

If there is anything unclear, please feel free to reply me and we will
follow up. I'm glad to work with you.
Have a great day.
Wen Yuan
Microsoft Online Community Support
===============================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
===============================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
F

Flomo Togba Kwele

Thanks for your reply, Wen.

I read the article you suggested. I did exactly what it said when
building the page originally.

I don't think the navigator is the problem. I don't think the
dataset.xsd file it created is filling the dataset from the
sqldataadapter, so that the navigator says there are no records in the
table, which is not true.

Do I have to code something in order for the dataset to be filled?

Thanks, Kwele
 
W

WenYuan Wang

Hi Kwele,
Thanks for your reply.

Base on my experience, if we drop a datasource into Form designer. VS IDE
will create BindingNavigator, DataGridView, Dataset, BindingSource,
TableAdapter for us.
The following code will also be added in the Form_Load event.
This.TableAdapter.Fill(Dataset.Datatable);

TableAdapater will get all rows thru database and fill records into
dataset.datatable.

For these reason, we don't have to code anything.
If you want to check whether the dataset has been filled, we would like to
suggest you can check whether there is any code added in the Form_Load
event.
For example:
private void Form1_Load(object sender, EventArgs e)
{

this.leasesTableAdapter.Fill(this.testDataBase20060908DataSet.Leases);
}
Please check the above and let me know whether it is the root case.

If there is anything unclear, please feel free to reply me and we will
follow up.
I'm glad to work you.
Have a great weekend!
Wen Yuan
Microsoft Online Community Support
(e-mail address removed)
 
W

WenYuan Wang

Hi Kwele

I haven't heard back from you two days. I just want to check if the issue
has been resolved? If it still persists, please don't hesitate to update
here. We'll go on to assist you on it.

Thanks.
Wen Yuan
 
B

Brice

I am experiencing the same problem.

When I drag the DataSource onto the form, it creates everything you have described, except a Table Adapter.

During page load, I do the following:

private void Employees_Load(object sender, EventArgs e)
{
// This Line calls a Helper (or Factory) method that
// returns and EmployeeDataSet.
this.employeeDataSet = EmployeeDataSet.GetEmployees();
}

Here is the code for the EmployeeDataSet.GetEmployees() method:

public static EmployeeDataSet GetEmployees()
{
EMPTableAdapter empAdapter = new EMPTableAdapter();
DEPTTableAdapter deptAdapter = new DEPTTableAdapter();
EmployeeDataSet empDS = new EmployeeDataSet();
empAdapter.Fill(empDS.EMP);
deptAdapter.Fill(empDS.DEPT);
return empDS;
}

I have verified during debugging that this dataset does contain data, but still, nothing is being displayed in my DataGridView control.

THANKS!!
 
B

Brice

I am experiencing the same problem.

When I drag the DataSource onto the form, it creates everything you have described, except a Table Adapter.

During page load, I do the following:

private void Employees_Load(object sender, EventArgs e)
{
// This Line calls a Helper (or Factory) method that
// returns and EmployeeDataSet.
this.employeeDataSet = EmployeeDataSet.GetEmployees();
}

Here is the code for the EmployeeDataSet.GetEmployees() method:

public static EmployeeDataSet GetEmployees()
{
EMPTableAdapter empAdapter = new EMPTableAdapter();
DEPTTableAdapter deptAdapter = new DEPTTableAdapter();
EmployeeDataSet empDS = new EmployeeDataSet();
empAdapter.Fill(empDS.EMP);
deptAdapter.Fill(empDS.DEPT);
return empDS;
}

I have verified during debugging that this dataset does contain data, but still, nothing is being displayed in my DataGridView control.

THANKS!!
 
R

RobinS

How did you bind your datagridview control to the dataset?
Can you show that code?

Robin S.
 
B

Brice

VS automatically created a Binding Source for me and named it "eMPBindingSource". The DataSource property is set to "employeeDataSet" and the DataMember property is set to "EMP".

The DataSource property for the DataGridView control is set to "eMPBindingSource".

Do I need to do anything other than fill the DataSet??

THANKS!!
 
B

Brice

I got it to work, but is this correct?

private void EmployeesView_Load(object sender, EventArgs e)
{
this.employeeDataSet = EmployeeDataSet.GetEmployees();
eMPBindingSource.DataSource = employeeDataSet;
eMPBindingSource.DataMember = "EMP";
}

The DataSource and Datamember have already been set at design time. Why do I have to set them again? Is there a method on the BindingSource that will force it to refresh itself?

Thanks!!
 
R

RobinS

No, that sounds right.

Can you put in a debug.print of eMPBindingSource.List.Count
after you fill the dataset and it is bound? What does it say?

Robin S.
 
R

RobinS

I guess it depends on how it was done at design time. By dragging
a dataset onto your form? Or did you do that by setting up an entry in
the DataSource table and then dragging that from the Data Sources
window?

If you look in the designer code, does it have the binding info
that you've done below?

Robin S.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top