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
Re: VB data table. loads data but doesnt save new data to DB
What does the code behind your save button look like?
-tg
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
Re: VB data table. loads data but doesnt save new data to DB
Re: VB data table. loads data but doesnt save new data to DB
Quote:
Originally Posted by
MoE70
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.
Re: VB data table. loads data but doesnt save new data to DB
Quote:
Originally Posted by
jmcilhinney
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
Quote:
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?
Re: Binding Navigator save
Bump. Help please. I still can't figure it out and I'm running out of time.
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.
Re: Binding Navigator save button implimentation
Quote:
Originally Posted by
jmcilhinney
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
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
Re: Binding Navigator save button implimentation
still no luck. im getting all sorts of errors nothing is working
http://img34.imageshack.us/img34/7852/untietled.png
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.
Re: Binding Navigator save button implimentation
no im using mysql. what is a place holder? can you explain please
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.