Bind optional one-to-one relationship to textbox

  • Thread starter Dan Davenport via .NET 247
  • Start date
D

Dan Davenport via .NET 247

I am working on a Windows Forms project in C#.

I'm looking for a way to bind an optional one-to-one relationshipto a textbox.

Here's why: I have a database that would work great with .NET ifI just had one record per person with 300 columns in eachrecord. For now, let's assume the data is all free text thatwill be entered from a form. Not all of these fields, however,will be entered, so the table would result in many null fields.What I would like to do, then, is have a table for each valuetype, linking back to a person table. I know that .NET willtreat this as a one-to-many relationship, where the personrecord is the parent and each property table linked to is achild.

Now -- I can use textboxes and bind from the relationship intothe text box and it works great for displaying the data. (aslong as you really do only have one child in the relationship!)The problem is when I want to enter data into a textbox thatdoes not correspond to an existing row in the database ordataset. (i.e. that property has not been added to that personyet) Although the textbox is technically bound, there is nodatarow corresponding to that particular control. This is not adataadapter update problem -- if I change the current positionof the binding context and come back, the value is not even inthe dataset any more.

I have noticed that the datagrid handles all of this entry intothe dataset very nicely. I can even create a new parent and newchildren and everything works out very nicely -- unique IDsmagically work out and everything is wonderful.

However.... I don't want to use a datagrid because I want theinterface to appear as though the option can be specified onlyonce.

So, here are my questions about various options I haveconsidered.....

1. Is there a way to make the textbox automatically insert thevalue into a new datarow if a corresponding row in the data setdoes not already exist? Is there a good way to do this in code?

2. Is there a way to make a datagrid appear as a textbox --display as one field, turn off ability to insert more than onerow. By turning off columns and all the headers and formatting,I've succeeded in making a datagrid appear as a text box withthe insert row below, but I need to get rid of the insert row ifI'm going to use it.

3. Currently I have a dataAdapter for each table. Is there a wayI can create a flattened xml schema so the dataset appears as agigantic unnormalized table?

4. Another option I have considered is flattening the database inthe dataadapter, but everything I have read discourages that.Plus, it would make creating my update/delete/insert commandsnightmarish.

5. A last resort, I guess, would be to just use a flatteneddatabase table, but I'm not big on that idea. Anyone had anyexperience with a sql server table with 300+ columns?

My guess is option 1 would be the best way to go if I can make itwork, but I'm not sure how to go about doing it. Anysuggestions?

Thank you!
Dan Davenport
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top