Using the .net Database Connection component

1qaz2wsx7

Member
Joined
Aug 16, 2007
Messages
17
Programming Experience
Beginner
Hi :)

I have an Access database and i want
to connect it to my software using the .net component and not through code, i succeded on doing that,
but i encountered caple of problems:

1) I have a MDI parent form and caple of child forms, and i want that
a table from the database will be presented on the datagrid in one of the child forms and the fields will be presented in another, according to the selection in the datagrid.

I secceded on doing that with the same form, but how can i do that
with diffrent child forms ?

2) I want that the same datagridview will have the option to present
caple of tables, i made the dataSource and the DataMember, and
made that diffrent buttons will apply diffrent Queries to filter the datagridview.
But, when i try to present a Query of diffrent table then what i put at
the beginnig, its putting the data inside the fields that have the same name, but not changing the all grid columns.

Why is that ? How can i do that ?

Here is the Query on the default table:
gridForm.ProjectsTableAdapter1.InProgress(gridForm.Db1DataSet.Projects)

After i use this Query i use this one, that apply to a diffrent table:
gridForm.SuperDataGridView1.DataMember = "Technicians"
gridForm.TechniciansTableAdapter.Fill(gridForm.Db1DataSet.Technicians)


It seems to put the data on a fields which have the same name,
but its not changing all the columns to the new table,
Why is that ?



Thanks.
 
Last edited:
Hi :)

I have an Access database and i want
to connect it to my software using the .net component and not through code, i succeded on doing that,
but i encountered caple of problems:

1) I have a MDI parent form and caple of child forms, and i want that
a table from the database will be presented on the datagrid in one of the child forms and the fields will be presented in another, according to the selection in the datagrid.

I secceded on doing that with the same form, but how can i do that
with diffrent child forms ?

Same way.. THink about it.. WHy does it work on one form? Because all the data is within the same dataset.. So logically, you give your second form access to the same dataset of the first form...

2) I want that the same datagridview will have the option to present
caple of tables, i made the dataSource and the DataMember, and
made that diffrent buttons will apply diffrent Queries to filter the datagridview.
But, when i try to present a Query of diffrent table then what i put at
the beginnig, its putting the data inside the fields that have the same name, but not changing the all grid columns.

Why is that ? How can i do that ?
Your question doesnt make sense to me, sorry

What are all the SQLs you want to use?


It seems to put the data on a fields which have the same name,
but its not changing all the columns to the new table,
Why is that ?
Oh, maybe I understand now..
You have a DataGridView, and it is, on the form designer, showing columns like
Name, Age, Phone, Height
And this is from the dataset table called People

But then during run time, youre changing the DataMember, so it is pointing to a different dataset table called Animals
And you see that the columns change but some are blank..The animals datatable has columns of Name, Age, Owner, Weight

And the grid still shows columns Name, Age, Phone, Height

And only Name and Age are populated


Of course.. its because the grid is made with those columns in design time,. and its set to not autogenerate columns at runtime

Delete that datagridview from the form and put a new one there NOT BOUND TO ANYTHING

That will autogenerate its columns at runtime..
 
Hi :)

Thanks for your answer.

Same way.. THink about it.. WHy does it work on one form? Because all the data is within the same dataset.. So logically, you give your second form access to the same dataset of the first form...

Yes i fought about it, but i faild on doing that,
how can i do that ? :confused:

I tryed to do it like that:
I created a new DataSource to the project,
and then i changed the DataSource on the datagridview to this
dataSet i just created, changed the dataMember to some table.
THen i went to the second child form, in the text box i changed the
DataBinding to the same datasSet and Choosed some Column at the same
table i chhosed for the datagridview.

But its not working :\


Of course.. its because the grid is made with those columns in design time,. and its set to not autogenerate columns at runtime

Delete that datagridview from the form and put a new one there NOT BOUND TO ANYTHING

That will autogenerate its columns at runtime..

Do you mean not to set the DataMember at design Time ?
But, when i dont choose his DataMember at design time,
thise lines are not working, they are not effecting the grid:
Me.SuperDataGridView1.DataMember = "Technicians"
Me.ProjectsTableAdapter1.InProgress(Me.Db1DataSet.Projects)



Or do you mean not to set the DataBinding at design time ?
If you mean to that, then i didnt changed that property it is not set
and the problem is still there. :\


Thanks.
 
Hi :)

Thanks for your answer.



Yes i fought about it, but i faild on doing that,
how can i do that ? :confused:
Same way you would give any object access to another object's data.. by giving the object a way to have the data passed

VB.NET:
Class Form2

  Public Sub SetDataSource(ds as Dataset)
 
    Me.MyBindingSource.DataSource = ds

  End SUb

End Class

Now call that..



I tryed to do it like that:
I created a new DataSource to the project,
and then i changed the DataSource on the datagridview to this
dataSet i just created, changed the dataMember to some table.
THen i went to the second child form, in the text box i changed the
DataBinding to the same datasSet
It's not the same dataset! It's another instance of a dataset of that type!

Basically, your neighbour bought a new car. You went and bought the same kind of car in the same colour from the same dealer. Now you are wondering why, when he fills his car up with gas, your car gas tank still shows empty? It's because they are different instances of the same types of cars!

This is a basic Object Orieted Programming concept.. You need to fully understand it or many things in .NET will baffle you..

What you need to do is get your neighbour to give you the keys to his car! Then when you get in the car the gas tank will look full!


Do you mean not to set the DataMember at design Time ?
But, when i dont choose his DataMember at design time,
thise lines are not working, they are not effecting the grid:

Please STOP USING QUOTE TAGS TO POST CODE. When I quote your post, the forum removes your quote blocks, so I cant see the code you;ve posted
http://www.vbdotnetforums.com/misc.php?do=bbcode


Or do you mean not to set the DataBinding at design time ?
THat's what I mean. Put an unbound grid on the form, ensure it set to AutoGenerateColumns = True, then set its DataSource to some datatable:

unboundGrid.DataSource = ProjectsTableAdapter1.GetInProgress()
 
Hi :)


I still cant do it, i dont know maybe i do everything wrong,
Can you please guide me step by step and show me how to do that ?
(from the very beginning).
Lets say i allready have 2 child forms, one contain a datagrid, the second contain a text box, i want to move trough the datagrid and see the content
of one column from the datagrid in the text box.

How can i do that ?

Thanks.
 
Ah, in that case:

VB.NET:
Class Form2

  Public Sub SetDataSource(bs as BindingSource)
 
    Me.MyBindingSource.DataSource = ds

  End SUb

End Class

Pass the bindingsource from form1, to form2
 
Hi :)


Still cant do it :\
I created new dataSource to the project,
then i created BindingSource to form1 and another one to form2.
I attached the BindingSource of form1 to the dataSet i created,
I attached the BindingSource of form2 to the dataSet i created,
then in form1_load i called the function you wrote in form2,
then attached the datagrid to form1 bindingSource and the textBox
to form2 bindingSource.

The textBox shows the data on the first line, and when i changing its value
the textBox changing too, but the textBox do not change when i move down to another line, its always on the first.


What is the problem ?


Thanks.
 
Last edited:
u misinterpreted cjard.

what he meant was (i hope i interpreted correctly)

create a binding source in the parent form, pass it to the child form? with a public method that he has given u

what u are doing now is setting 2 binding source unrelated to each other, it doesnt have that erm inheritance capability (when u move the parent, ur child moves too)
 
I attached the BindingSource of form1 to the dataSet i created,
I attached the BindingSource of form2 to the dataSet i created,

To expand a little on what alander is saying:

BindingSource is the thing that maintains position within a list of values. If you have 2 bindingsources, you can look at 2 different locations in the list at the same time. This is why you still dont see the controls on form2 change when you move the Position of bindingsource1 -

Form1 BindSOurce is looking at row10, but form2 bindsource is looking at row1


What you can do (easiest way) is have BindingSource2 look at BindingSource1 NOT at the dataset independently. When bindingsource 1 changes, bindingsource 2 will see the change.

You could, actually, if you did a LOT of work, make all the controls share 1 bindingsource, but that is a LOT of hard work for the sake of saying:

bs2.DataSource = bs1
 
what u are doing now is setting 2 binding source unrelated to each other, it doesnt have that erm inheritance capability (when u move the parent, ur child moves too)

it's not quite inheritance or relations.. Instead imagine you have a TV in one room, and lots of people are watching it. Now you have another TV in another room on a different channel and lots of people are watching that.
The 2 TV can change independently.

Now, pull the cable out of TV 2 and wire it up to a camera instead. Now point the camera at TV 1. All the people now watch the same channel, and, imagine.. it is a lot easier to install one camera, than move 200 people into the same room as TV1

The TV is the BindingSource, the hundreds of people are the Controls linked to the bind source..
 
Back
Top