Results 1 to 11 of 11

Thread: [RESOLVED] Add New Code

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    38

    Resolved [RESOLVED] Add New Code

    Hey everybody. I am somewhat new to DB programming, and I am struggling to get a grasp on the fundamentals.

    I am trying to write the code the VB generates when you drag a table onto a form. The specific code I am looking for is the code that controls the "ADD NEW" plus symbol button on the binding navigator toolbar that pops up. I feel if I can get a good idea of the code behind these things, I will be on the right track.

    If anyone can help, it would be highly appreciated.

    Thanks

  2. #2
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Add New Code

    Do you mean the code that defines the form itself? I'm not sure why you'd want to look at this but you can just open the form object in wordpad to see all hidden code.

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    38

    Re: Add New Code

    I am looking for the code that comes along with the autogenerated toolstrip that appears on the form when you drag a table from the datasources onto the form.

    I would like to see the code because I want to model other code on its functionality.

    I have tried opening it in Notepad, but I see the same code as in VB code window. I know the "Add New" button has code behind it, as it has functionality. I just cant find this code.

    Thanks for your help.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Add New Code

    Are you using Classic VB (VB6 and earlier) or VB.Net (VB 200x)?

    If you are using Classic VB, you cannot get the code.. but you can have a much better alternative that has fewer problems - which is to use code to work with database rather than the controls. See the ADO Tutorial link in my signature for explanation/example.

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Add New Code

    I've been waiting for someone to ask these questions, but since no one has, I will.

    I have no idea what you are referring to. Is this an Access database?
    Quote Originally Posted by theun789
    I am trying to write the code the VB generates when you drag a table onto a form.
    What VB generated code? How do you "drag" a database table onto a form?

    What is an "autogenerated toolstrip"?

    What "Add New" button?

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    38

    Re: Add New Code

    I am using VB 2005

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Add New Code

    What type of database are you using?

  8. #8

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    38

    Re: Add New Code

    Sorry for being unclear. I am working in VB2005 Standard Edition.

    I am connected to a remote SQL database on a server.

    Within my program I have a dataset that refernces the tables in the database.

    Using VB2005, I am able to drag a table from the Data Sources sidebar onto a form. When I do this, VB creates the neccesary connections, and adds either a datagrid view, or details view (w/ text boxes). It also adds a navigating toolbar to the top of the form. This toolbar has left, right, first, and last navigation buttons to go between existing records. It also has a save button which will propogate changes back to the database. There is an additional button on this toolbar, an "Add new" button. I am trying to find what the code behind this button would be. In essence, it initializes a new row in the table, and then allows the user to enter the neccesary data. This is the code I would like to undertand.

    Thanks to everyone for your help so far

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Add New Code

    AddNew is a SQL Insert statement. The "Save" button is a SQL Update statement. (That may not be the actual code the controls generate, but it's how you code AddNew and Save.)
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  10. #10

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    38

    Re: Add New Code

    So the setup I have currently consists of a combobox bound to the Primary key of the table. As I change the selected index, the text boxes below update to reflect the data corresponding to the chosen row.

    I want to code a button that will initiate this insert command you refer to. IE combobox will have next value (it is auto-incremented) and the text boxes will be open for data.

    Any help on how to code this?

    Thanks

  11. #11

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    38

    Re: Add New Code

    The code I was looking for turned out to be rather simple.

    Me.ClientBindingSource.AddNew()

    Sorry for any wasted time, and thanks for the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width