none
How do I allow users to save old files and create new ones, in an access database, using the same gridview, dataset, tableadapter and datasource? RRS feed

  • Question

  • I have a winforms application that uses an access database to store documents created by end users. the access database has two alterable tables linked through a master detail relationship. the first table, the master, is called chapters, containing an ID and chapter fields. the second table is called scenes and has an ID, a foreign key called chapterID and name, etc fields. I have two grids on two different forms; one form contains the chapter table alone and is used to update chapter names while the other form uses a treeview and grid for the scenes table, the treeview, containing the chapter names, being used as a navigator the gridview, which contains the scenes table data.

    What I want is to have a file new option that lets the end user create more than a single book. Thus, I want a menu that will allow them to create another book while saving the dataset for the first book in some kind of file. They'd be able to reload it whenever they wanted, through an open button on the menu. Do I use the readXML, writeXML, getXML methods for this in the click events of the menu items?

    What I was thinking is that they'd be able to clear the 2 tables of their data, through a wizard, and add new data for a new title.

    My question is therefore, how do I approach this? Since the formload will contain a link to one dataset, I want to know if I should write the data from the database into xml files or text files, for each book they want to write, then load new data by creating a wizard and new xml file; a wizard, in essence, that creates a new xml file for each book or title and populates the same tables in the access database. In that way I would not have to change the tableadapter and fill statements. I have spent some time researching the approach. On the other hand, I don't know if I should create, in code, new tables for each and every title they wish to start, thus making new datasets, adapters, etc, and do select case items in the form load. Please help me with an approach and with the code I might need to do this. Thank you.


    dcw

    • Edited by ddsharper1 Sunday, March 13, 2011 5:04 AM creating clarity
    Sunday, March 13, 2011 4:53 AM

Answers

  • Thank you for the follow up and the suggestions. Unfortunately, my coding skills are weak so I finally got help from a very generous VB tutor, across the atlantic and from youtube. He used team viewer, got on my computer, created the database, worked code magic and after several days and many hours, completed the project for me. An amazing vb coder. I wish more tutorials dealt with real problems, explained step by step the whats and whys and used copious dialog to teach so that the learning curve could approach 30 instead of staying at 90 degrees. Thanks.
    dcw
    Monday, March 28, 2011 8:21 AM

All replies

  •  

    Hi ddsharper1,

    Welcome!

    According to your description, I got something for it, I hope I am in right direction.

    Your requirement is let user create a new book, I think every data is valuable, so we should not clear them, and use XML in your scenario may not a good way. I think you should restructure your database.

    Table: Books (BookID, BookName, User,CreateTime and updatetime etc. deleted)

    Table: Chapters (ChapterID, ChapterName, BookID(FK), etc.)

    Table: Scenes (ScenesID, ScenesContent, BookID(FK), etc.)

    The relationship may one book contains many Chapters and one chapter contains many scenes.

    If you want to create a book, you can insert related records into the three tables, just set deleted to true if you want to delete a book in your database.

     

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 14, 2011 8:51 AM
    Moderator
  • Thank you so much for your response, it makes complete sense. I was going around in circles due to a limited perspective. That is a whole new way of looking at the problem, since, when I initially began building this little part of the program, I never thought about multiple books, and only thought about the regular coding examples, employees and orders, for instance, of master-detail relationships with 2 instead but not 3 tables. I will try to code for this. If I have a problem I will ask for your help, if that is okay. Thanks again.
    dcw
    Monday, March 14, 2011 5:47 PM
  • I have wasted this whole day trying to figure out how to do what I need. currently i have a treeview for chapters and grid for the scenes. I added the book table and a characters table. I want the book to show up, the associated chapters and then the scenes. the characters may or may not be involved but nothing seems to work. I need master-detail, detail, detail hierarchically arranged. Here is my current code. Worked with access and, I don't know. I wanted the root node, currently named root, to reflect the book name. I am at a loss as to how to maintain the treeview, change the values and have book titles included too.

    Private

     

    Sub ChaptersTableBindingNavigatorSaveItem_Click()

    Validate()

    ChaptersTableBindingSource.EndEdit()

    TableAdapterManager.UpdateAll(chapDataSet)

     

    End Sub

     

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

     

    'TODO: This line of code loads data into the 'chapDataSet.SceneTable' table. You can move, or remove it, as needed.

    SceneTableTableAdapter.Fill(chapDataSet.SceneTable)

     

    'TODO: This line of code loads data into the 'SceneDataSet.ChaptersTable' table. You can move, or remove it, as needed.

    ChaptersTableTableAdapter.Fill(chapDataSet.ChaptersTable)

     

    'Build the tree

     

    Dim ID As String

     

    Dim ChapterName As String

     

    Dim I As Integer

     

    For I = 0 To chapDataSet.ChaptersTable.Count - 1

    ID = chapDataSet.ChaptersTable.Rows(I).Item(0)

    ChapterName = chapDataSet.ChaptersTable.Rows(I).Item(2)

    TreeView1.Nodes(0).Nodes.Add(ID, ChapterName)

     

    Next

    TreeView1.ExpandAll()

     

    End Sub

     

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect

     

    If TreeView1.SelectedNode Is Nothing Then

    DGV.DataSource =

    Nothing

     

    Exit Sub

     

    End If

     

    If TreeView1.SelectedNode.Name = "root" Then

    DGV.DataSource =

    Nothing

     

    Exit Sub

     

    End If

     

    Dim ID As String = TreeView1.SelectedNode.Name

    DGV.DataSource = chapDataSet.SceneTable.Select(

    String.Format("ID={0}", ID))

     

    End Sub


    dcw
    Tuesday, March 15, 2011 8:12 AM
  • Hi,

    Do you mean this structure:

    --Book1

    ----Chapter1

    ----Chapter2

    --Book2

    ----Chapter1

    ----Chapter2

    You can add information to node's tag, when you afterselect the node, you can get the node's information from the tag, This question is relates to WinForm, You just to foreach the records in dataset.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 16, 2011 6:41 AM
    Moderator
  • Here is the structure I want. Each book has its own set of chapters and each chapter its scenes and each book has its own set of characters and each character its own set of characteristics.

    Book1

    Chapter1

    ---scene1

    ---scene2

    ---scene3

    ---scene4

    Chapter2

    ---scene1

    ---scene2

    ---scene3

    ---scene4

    ---scene5

    Chapter3

    ---scene1

    ---scene2

    ---scene3

    ---scene4

    Book1

    ---Characters

    -----character1

    ------name

    ------age

    ------role

    ------occupation

    ------etc

    ---character2

    ------name

    ------age

    ------role

    ------occupation

    ------etc

    --character3

    ------name

    ------age

    ------role

    ------occupation

    ------etc

    Book2

    ---Characters

    ------character1

    ------name

    ------age

    ------role

    ------occupation

    ------etc

    character2

    name

    age

    role

    occupation

    etc

    character3

    name

    age

    role

    occupation

    etc


    dcw
    Friday, March 18, 2011 3:52 AM
  • Hi,

    Thanks for your feedback!

    I got your point, I think your problem relates to How to use the TreeView control, First you can use ADO.NET to retrieve all the Book into a list, then you can use each bookid to retrieve a list of chapters, last you can use chapterid to retrieve a list of other information.

    This is the logic of your application, but if you want to how to bind the records to the listview, I think you should repost here: http://social.msdn.microsoft.com/Forums/en/winforms/threads

    Thanks for understanding.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 22, 2011 1:16 AM
    Moderator
  • Hi dcw,

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions? 
     
    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 28, 2011 1:23 AM
    Moderator
  • Thank you for the follow up and the suggestions. Unfortunately, my coding skills are weak so I finally got help from a very generous VB tutor, across the atlantic and from youtube. He used team viewer, got on my computer, created the database, worked code magic and after several days and many hours, completed the project for me. An amazing vb coder. I wish more tutorials dealt with real problems, explained step by step the whats and whys and used copious dialog to teach so that the learning curve could approach 30 instead of staying at 90 degrees. Thanks.
    dcw
    Monday, March 28, 2011 8:21 AM
  • Hi ddsharper1,

    Gald to hear this, Coding is a interesting thing, but there are really a lot of things waiting for us, I think MSDN is a good platform to learn, but We couldn't help coding a project for you, We can give suggestions and directions if you have any problems about technical points. welcome!

    Have a nice day. 


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 28, 2011 8:53 AM
    Moderator
  • What do you mean in your statement; we couldn't help coding a project for you? What does that mean? thank you. d
    dcw
    Tuesday, March 29, 2011 8:53 AM
  • Hi ddsharper1,

    My bad English! I mean we will try our best to help you, but we also hope you can learn something from here, pratice makes perfect!

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 29, 2011 8:58 AM
    Moderator