How to bind multiple tables to a binding navigator using data source wizard in C# - ado.net

How to bind multiple tables to a binding navigator using data source wizard in C# so that when textbox1 value changes the values in other textboxes should be change which contains data from other table. tables have foreign key relationships.

The BindingNavigator should have a BindingSource value set to the BindingSource object of your "parent" or "master" table in the dataset (same as textBox1). The "other table" controls should have a BindingSource object that points to the "child" datatables. If your relationships are properly setup then when you change the master/parent record with the bindingnavigator then the detail/child records will update accordingly
Basically, the binding source for your "other tables" should have a DataSource value pointing to the BindingSource of your primary table (the binding source of textbox1) and
should have a DataMember value of the relationship/FK that points to the respective secondary table.
If you are using drag and drop datasources then be sure you are dragging over the data sources that utilize the relationships. So say you created a dataset with 3 tables with tiered relationships: Grandparent, Parent, Child. In your Data Sources window you will see all three datatables side by side. You are probably dragging the desired Grandparent field over and getting your binding navigator, binding source, and textbox created, correct? You might think you are supposed to then use those side-by-side root-level Parent and Child datasources but that is WRONG. Expand the Grandparent source and at the end of columns listed you will see Parent listed again nested underneath Grandparent. Expand that and use those columns. At the bottom of that nested Parent you will see a Child data source that you can expand and use columns from.

Related

Combine fields from two tables into one autocompletebox

I have two tables "Services and Projects". Both tables have a "Name" field. I would like to take both fields from both the tables and put them into a single autocompletebox in one of my screens. I searched around and found different methods of doing this but not in LightSwitch. Any ideas?
If I understand your requirement correctly, you want the Name property from both Services and Projects to appear in a single textbox? If this is the case, my approach would be as follows:
Use a view on the data source to union the Projects and Services data sources
Add that view to your data model (on a new data connection)
Define Name as the summary property for the new view-based entity.
Add the view to your screen as a separate query
Add the view data object to your screen as an auto-complete box.
WARNING: You'll also need code-behind to identify whether the value selected is a Project or a Service and to apply this value to the relevant field in your linked entity.

Entity Framework - Entity not added to design surface

I attempted to update my edmx file by selecting a table. The tool spit out a info message that said the table did not have a primary key.
The entity did not get added to the design surface but it did get added to the .edmx file. In addition, using the model browser I see an Entities.Store and an Entities. My table got added to Entities.Store, but not to Entities.
I cannot access the table that was "added" in the code.
What do I do?
Steps to reproduce:
Create a SQL table with two columns that are both defined as foreign keys to other tables. Make sure the tables that the FKs point to already exist in the model on the design surface.
Right click and choose Update Model from Database...
Next. Under the Add tab, mark the new table under Tables
Click Finish.
An association will be created and it will be selected on the design surface, but it won't start with FK_, it will just be the name of your table. Go to the Model Browser and look under Entity Types. The table will not be there. Look under Associations and you will see your table name there as an association, but it will look out of place (because of the name).
Entity Framework was too smart for me. It created an association instead of an entity. Odd, but it works for how I need to use it.

Create One-to-One relationship based on PK of both tables

I'm really new to Entity Framework (currently using EF5) and vs2012 and am having difficulty trying to figure something out.
I have an .edmx that was generated from my database. It has two tables in it: Item and 3rdPartyItem. In short, the Item table is the main table for all the company items while the 3rdPartyItem table is a table that is used to hold additional attributes for items. This 3rdPartyItem table was created by an outside company and is used with their software for the company, so I can't mess with either table. What I'm trying to do is show a list of Items in a grid but I need to show a combination of all the fields for both tables. In vs2012, if I create a relationship and make it 'zero-to-one' (because for each record in the Item table, there doesn't necessarily have to be one in the 3rdPartyItem table), vs complains about not being mapped correctly. When I set the mapping, it then complains that there's multiple relationships. I did some research and found that you can't create a relationship with 2 primary keys, so I was thinking that was the problem. But how can I change the .edmx so that in code, I can access Items and 3rdPartyItem like so:
var items = dbContext.Items;
items.3rdPartyItem.SomeField <--field from 3rdPartyItem table.
not too sure if it's even possible, but it would be very, very helpful if so. Any ideas?
What you're looking for is table-per-type (TPT) mapping inheritance. You can view an MSDN walkthrough here (although you'd want your base type to be instantiable):
http://msdn.microsoft.com/en-us/data/jj618293.aspx

Ghost change my data after close form

I have a little databes in access. I make a few forms with sub forms and drop list(by query):
Steps of my creating form:
make form from table
delete all not PK or FK text box
create comboBox with store value to text box what I choase
create subForm and set Link Master Fields and child fields
design view:
This is form for table Task task have Fk: Project, peson etc. DropLists are connected tu subform for changing FK like project, person etc. So when I work i select in droplists what i want add to database and work with subForm. When I close this form, the first row in table change FK to last configuration on droplists.. Pleas how can I fix it?
It is quite possible to use a main form for selecting and updating subform records, but in this case it should not be a bound form.
To set up, for want of a better word, a linking form, unbind the main form, that is remove the record source and ensure the dropdowns (comboboxes) do not have control sources. I suggest you rename the dropdowns to cbo, to indicate that they are controls, not fields. The hidden controls should not be needed.
The value of a combobox is the value of the bound column. The Key or FK is the first item in your SELECT statement and the bound column is 1 (one) so the relevant Key or FK is the value of each comboboxe. You can set the link master fields to the names of controls so the Link Master Fields should be cbo_id_projekt;cbo_id_os_udaje;cbo_id_komponent;cbo_id_uloha.
As an aside, I generally avoid underscores, but each to their own.

How do I get the column name from an Entity Framework Association

I have an entity model built using the designer. In one of my tables (application), I have several foreign keys that reference the same status (status) table. As a result, when my associations were built, I have several entity objects built with an auto indexing name:
application_statuses2
application_statuses3
etc.
I'm building a "version history" type screen and want to be able to properly list the "friendly name" for each column modified. For example, I want to display "Destination Status" will be displayed instead of "application_statuses2". If I can determine the endpoint column name on the association in question, I can setup the proper display value.
I can find the entity object in the designer, I can even track where it references the foreign key in question that built the association, but I can seem to find the property that outlines the enpoints or column names. How do I determine the column name, or endpoint, on my association, or entity?
I wish it were more ready to hand, have been looking for it as well. Bit of a pain when you have multiple FKs to the same table.
Click on the navigation property you want to check
Under properties, look at the name of the association
At the top of properties, use the object navigator dropdown to switch to the association
Click into the 'Referential Constraint' property
Use the ellipses button on the right to bring up the column names
Dont know if there is a better way of doing this, but I certainly hope so!