Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Master/Detail on a form

soweyoungsoweyoung Posts: 2Member
Hi there.
I am currently working on a windows form that has master and detail sections on it. I have about 12 textboxes and comboxes bound to a dataset for the master section and navigation buttons to go back and forth through the dataset. I also have a datagrid control for the detail section which is related to the master section. I have managed to populate master and detail section's records on the form using data adapter and dataset and I have also got the update part sorted out.
The only problem I have is adding a new record to a master section.
I have used "BindingContext(dataset, "table").AddNew()" method and also tried to add datarow and add a new row to dataset, but no luck so far.
Could any one give some clue how to add a new record in this situatin.
Any comments and helps would be appreiciated. Thanks.

Comments

  • VCGVCG Posts: 51Member
    Hey there Soweyoung. how are you? regarding your problem about adding rows in a dataset, here's how i work at it.

    on your ADD Procedure............
    [code]
    Dim rowTemp as DataRow
    Dim tblTemp as DataTable = Datasetname.Tables("TableName")
    rowTemp = Datasetname.TableName.NewRow()

    'HERE IS WHERE YOU OUT ITEMS YOU NEED TO ADD TO YOUR DATASET
    rowTemp.Item("FieldName1") = "value for Fieldname1"
    rowTemp.Item("FieldName2") = "value for FieldName2"

    'THIS LINE IS THE ACTUAL LINE THAT WILL ADD THE DATA YOU ENTERED ABOVE TO THE DATASET
    tblTemp.Rows.Add(rowTemp)
    [/code]

    you will have to supply the right values of course.
    Datasetname = the name of your Dataset on the form
    tablename = the name of the table on your dataset (usually the same name on your underlying database. I just noted it because it is possible to have Dataset without a database.)
    Fieldname = the name of the Field on the Dataset(usually the same as on the Database)

    Putting values on the line rowTemp.Item("FieldName")="value" is optional, however, I showed it here so that if you have a Constraint/Restriction/Relationship either on your Database or on the Dataset, you can put that value in that section otherwise this code will cause an exception

    Also, you can always overload the program instead of using variables above to make the code shorter and get rid of variables. however, for clarity's sake, and for readability reasons i used the 2 variables. I always do that rather than overloading. o, and by the way, the newly added recordset is at the eof. just use your navigational code to go to the last entry on the table automatically within the above procedure.

    the above is one way of Adding Recordset in a Dataset. however, there is a much simpler and easier method. you go to the properties of the adapter, then you will have to supply the SQL command on the INSERT command properties, and then just call it from within the program. It works well with DataGrid.

    Have FUN!!!!

    : Hi there.
    : I am currently working on a windows form that has master and detail sections on it. I have about 12 textboxes and comboxes bound to a dataset for the master section and navigation buttons to go back and forth through the dataset. I also have a datagrid control for the detail section which is related to the master section. I have managed to populate master and detail section's records on the form using data adapter and dataset and I have also got the update part sorted out.
    : The only problem I have is adding a new record to a master section.
    : I have used "BindingContext(dataset, "table").AddNew()" method and also tried to add datarow and add a new row to dataset, but no luck so far.
    : Could any one give some clue how to add a new record in this situatin.
    : Any comments and helps would be appreiciated. Thanks.
    :



Sign In or Register to comment.