Results 1 to 14 of 14

Thread: Binding Navigator save button implimentation

  1. #1

    Thread Starter
    Addicted Member MoE70's Avatar
    Join Date
    May 2006
    Posts
    185

    Binding Navigator save button implimentation

    Hi

    I've got a datable on my form, it loads the data from the database and displays it just fine but when i add data to it it doesn't save it to the database...

    I don't know why but the save button on the data navigator is disabled by default but even when i enable it, enter data and click it, it doesn't save the data. (i dont think its the button i just thought it's worth mentioning that the save button is disabled by default when you drag a data table onto a form)

    Anyone know a solution? or can someone try it and tell me if they have the same problem
    Last edited by MoE70; Apr 18th, 2010 at 07:16 PM.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: VB data table. loads data but doesnt save new data to DB

    What does the code behind your save button look like?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Addicted Member MoE70's Avatar
    Join Date
    May 2006
    Posts
    185

    Re: VB data table. loads data but doesnt save new data to DB

    theres no code behind any of the buttons even the 'next record' and 'repvious record' and they work fine. its all hidden somewhere. BTW this isnt a normal button its the save button on the Binding Navigator tool

  4. #4

    Thread Starter
    Addicted Member MoE70's Avatar
    Join Date
    May 2006
    Posts
    185

    Re: VB data table. loads data but doesnt save new data to DB

    bump

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: VB data table. loads data but doesnt save new data to DB

    Quote Originally Posted by MoE70 View Post
    theres no code behind any of the buttons even the 'next record' and 'repvious record' and they work fine. its all hidden somewhere. BTW this isnt a normal button its the save button on the Binding Navigator tool
    The BindingNavigator itself provides the code internally for navigating the data. It does NOT provide the implementation for saving the data. It simply provides the interface. It's up to you to handle clicks on that Save button and save the data. That's because every single app will require different code for saving data, while navigating requires exactly the same code every time.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Addicted Member MoE70's Avatar
    Join Date
    May 2006
    Posts
    185

    Re: VB data table. loads data but doesnt save new data to DB

    Quote Originally Posted by jmcilhinney View Post
    The BindingNavigator itself provides the code internally for navigating the data. It does NOT provide the implementation for saving the data. It simply provides the interface. It's up to you to handle clicks on that Save button and save the data. That's because every single app will require different code for saving data, while navigating requires exactly the same code every time.
    I've been trying to get it to work all day but no luck

    I've got the following code in for my save button

    Code:
            Me.TeamProjectWAMP.BeginInit()
            Me.Validate()
            Me.PositionsBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.TeamProjectWAMP)
    but i get an error
    ExecuteReader: CommandText property has not been initialized

    I'm supposed to provide the insert mysql query or something but i dont know how or where.

    any ideas?

  7. #7

    Thread Starter
    Addicted Member MoE70's Avatar
    Join Date
    May 2006
    Posts
    185

    Re: Binding Navigator save

    Bump. Help please. I still can't figure it out and I'm running out of time.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Binding Navigator save button implimentation

    First up, get rid of those BeginInit and EndInit calls. You want to call Validate on your form. If that returns True, then call EndEdit on your BindingSource and UpdateAll on your TableAdapterManager.

    As for that error message, the SQl code should be generated automatically for most typed DataSets. If yours hasn't been then it means that either one or both of the following conditions are true:

    1. The database table from which a DataTable/TableAdapter was generated doesn't have a primary key or the primary key wasn't returned by the query.

    2. The DataTable/TableAdapter was generated from a query that includes multiple database tables.

    Either fix your database and regenerate your Data Source so that those are not the case, or else you'll have to go into the DataSet designer and provide the SQL code for the action commands (DELETE, INSERT, UPDATE) yourself.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Addicted Member MoE70's Avatar
    Join Date
    May 2006
    Posts
    185

    Re: Binding Navigator save button implimentation

    Quote Originally Posted by jmcilhinney View Post
    First up, get rid of those BeginInit and EndInit calls. You want to call Validate on your form. If that returns True, then call EndEdit on your BindingSource and UpdateAll on your TableAdapterManager.

    As for that error message, the SQl code should be generated automatically for most typed DataSets. If yours hasn't been then it means that either one or both of the following conditions are true:

    1. The database table from which a DataTable/TableAdapter was generated doesn't have a primary key or the primary key wasn't returned by the query.

    2. The DataTable/TableAdapter was generated from a query that includes multiple database tables.

    Either fix your database and regenerate your Data Source so that those are not the case, or else you'll have to go into the DataSet designer and provide the SQL code for the action commands (DELETE, INSERT, UPDATE) yourself.
    My tables all have a primary key and its just 1 table per form/navigator.

    When I go to the dataset design, I don't know what to enter for the INSERT query. for SELECT its easy because you're just getting all the data from the table. but for insert how would you write it. insert what into what column?.... i mean that depends on what the user enters so how can it be provided before hand? i dont understand. also would it be possible for you or anyone else to have a look at the problem first hand by remote desktop or if i upload it or something

    thanks

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Binding Navigator save button implimentation

    The insert query is just that... an insert query:
    Code:
    INSERT INTO tblSomething (field1, field2, field3) VALUES (@Param1, @Param2, @Param3)
    Then in a later step of the wizard, you link the fields to the parameters... That's what tells the adapter, hey, this field of my datatable relates to this parameter in my query.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11

    Thread Starter
    Addicted Member MoE70's Avatar
    Join Date
    May 2006
    Posts
    185

    Re: Binding Navigator save button implimentation

    still no luck. im getting all sorts of errors nothing is working



  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Binding Navigator save button implimentation

    Is Access your database? If so then you'll have to use ? as a parameter place-holder in the designer.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13

    Thread Starter
    Addicted Member MoE70's Avatar
    Join Date
    May 2006
    Posts
    185

    Re: Binding Navigator save button implimentation

    no im using mysql. what is a place holder? can you explain please
    Last edited by MoE70; Apr 20th, 2010 at 12:00 AM.

  14. #14
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: Binding Navigator save button implimentation

    MySql also uses ? as a placeholder. Try:

    Code:
    INSERT INTO Users(UserName,Password) VALUES (?UserName,?Password)
    UserID is the primary key column so I doubt you would want to insert into it as it should be set to autogenerate.

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