datagrid deleterow
help, i had this error for weeks
i just had a table in my database
i dragged it over to my form as datagrid from datasource
the table adaptor is automatically created for me
binding navigator is too created, in which i have delete and save button
however, as i delete a user-selected row, and refresh it
the row is back
if i tried to delete then save i have errorPrivate Sub POS_session_BindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles POS_session_BindingNavigatorSaveItem.Click
Me.Validate()
Me.POS_session_BindingSource.EndEdit()
Me.POS_session_TableAdapter.Update(AJEPOSdataDataSet)End Sub
error:"Update requires a valid DeleteCommand when passed DataRow collection with deleted rows."
error occurs at "Me.POS_session_TableAdapter.Update(AJEPOSdataDataSet)"i had read a little around and it seems that i need some olecommandbuilder thing, but i dont understand how to build one
i dont get how i can just add a new row and updateall, but i cant delete...
Answers
istaris wrote: error:"Update requires a valid DeleteCommand when passed DataRow collection with deleted rows."
error occurs at "Me.POS_session_TableAdapter.Update(AJEPOSdataDataSet)"Hi istaris,
You are making a database access application with Data Wizard.
"Update requires a valid DeleteCommand when passed DataRow collection with deleted rows."
The error indicates the DeleteCommand property of your POS_session_TableAdapter object is not valid or not set. Please make sure you have set primary key in the table.
How to check: Right-click AJEPOSdataDataSet.xsd file in Solution Explore -> View Designer -> Select/Click POS_session_TableAdapter -> In Properties pane you will see these properties: DeleteCommand, UpdateCommand, InsertCommand and SelectCommand.
Please check CommandText part of DeleteCommand, it should be like this:
DELETE FROM Table WHERE (PKField = ?)
Actually you have to define these properties for the TableAdapter object:
DeleteCommand, UpdateCommand, InsertCommand and SelectCommand.
---------------------------------------------------------------------------------------------
Follow these steps to make a data access project using BindingNavigator control, above Command properties will defined automatically and it will work fine:
Presume using an Access database StaffDB.mdb which has a table Staff.
The table has four fields (Text type):
StaffNumber (set as Primary key)
StaffName
Department
Location
1. Data menu -> Add New Data Source
During wizard, select StaffDB.mdb and Staff table, finishing it will create a StaffDBDataSet.xsd file in Solution Explorer.
2. Data menu -> Show Data Sources
In Data Sources panel, drag&drop each data field to Form in turn in order to bind individual data.
During this process, the StaffDBDataSet, StaffTableAdapter, StaffBindingNavigator and StaffBindingSource controls will be added automatically to Form, and four pairs of Label and TextBox controls will be added to Form.
3. Set StaffBindingNavigator.BindingSource property as StaffBindingSource in Properties panel.
4. Set StaffBindingSource.DataSource property as StaffDBDataSet in Properties panel.
5. Add code in Form1.vb to Save event handle.
Code BlockPrivate Sub StaffBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripButton.Click
Me.Validate()
Me.StaffBindingSource.EndEdit()
Me.StaffTableAdapter.Update(Me.StaffDBDataSet.Staff)
Me.StaffDBDataSet.AcceptChanges()
End Sub
6. Right-click the database file StaffDB.mdb in Solution Explorer -> change the "copy to output directory" property to "copy if newer".
That’s all.
Here is the corresponding illustration:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2445804&SiteID=1
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2395775&SiteID=1
--------------------------------------------------------------------
In addition, you can make a database access application using pure code instead of Data Wizard.
Including such features as Next, Previous, First, Last, Update, Delete, Insert, Save.
Please check my posts inside this thread.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2471782&SiteID=1
Here is the corresponding illustration:

Regards,
Martin
All Replies
istaris wrote: error:"Update requires a valid DeleteCommand when passed DataRow collection with deleted rows."
error occurs at "Me.POS_session_TableAdapter.Update(AJEPOSdataDataSet)"Hi istaris,
You are making a database access application with Data Wizard.
"Update requires a valid DeleteCommand when passed DataRow collection with deleted rows."
The error indicates the DeleteCommand property of your POS_session_TableAdapter object is not valid or not set. Please make sure you have set primary key in the table.
How to check: Right-click AJEPOSdataDataSet.xsd file in Solution Explore -> View Designer -> Select/Click POS_session_TableAdapter -> In Properties pane you will see these properties: DeleteCommand, UpdateCommand, InsertCommand and SelectCommand.
Please check CommandText part of DeleteCommand, it should be like this:
DELETE FROM Table WHERE (PKField = ?)
Actually you have to define these properties for the TableAdapter object:
DeleteCommand, UpdateCommand, InsertCommand and SelectCommand.
---------------------------------------------------------------------------------------------
Follow these steps to make a data access project using BindingNavigator control, above Command properties will defined automatically and it will work fine:
Presume using an Access database StaffDB.mdb which has a table Staff.
The table has four fields (Text type):
StaffNumber (set as Primary key)
StaffName
Department
Location
1. Data menu -> Add New Data Source
During wizard, select StaffDB.mdb and Staff table, finishing it will create a StaffDBDataSet.xsd file in Solution Explorer.
2. Data menu -> Show Data Sources
In Data Sources panel, drag&drop each data field to Form in turn in order to bind individual data.
During this process, the StaffDBDataSet, StaffTableAdapter, StaffBindingNavigator and StaffBindingSource controls will be added automatically to Form, and four pairs of Label and TextBox controls will be added to Form.
3. Set StaffBindingNavigator.BindingSource property as StaffBindingSource in Properties panel.
4. Set StaffBindingSource.DataSource property as StaffDBDataSet in Properties panel.
5. Add code in Form1.vb to Save event handle.
Code BlockPrivate Sub StaffBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripButton.Click
Me.Validate()
Me.StaffBindingSource.EndEdit()
Me.StaffTableAdapter.Update(Me.StaffDBDataSet.Staff)
Me.StaffDBDataSet.AcceptChanges()
End Sub
6. Right-click the database file StaffDB.mdb in Solution Explorer -> change the "copy to output directory" property to "copy if newer".
That’s all.
Here is the corresponding illustration:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2445804&SiteID=1
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2395775&SiteID=1
--------------------------------------------------------------------
In addition, you can make a database access application using pure code instead of Data Wizard.
Including such features as Next, Previous, First, Last, Update, Delete, Insert, Save.
Please check my posts inside this thread.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2471782&SiteID=1
Here is the corresponding illustration:

Regards,
Martin
thk very very much, i feel infinitely dumb after i solved it

