• 0

VB.net datagrid editing


Question

4 answers to this question

Recommended Posts

  • 0

I don't have time to explain this in detail, but here's the basics...

1. Right click your datagrid and go to 'Property Builder'. Go to the 'Columns' section.

2. Add an 'Edit, Update and Cancel' column from the 'Button Column' node. Click OK.

3. In the code behind, select the DataGrid from the drop down list at the top left, then select the 'Edit Command' from the drop down list at the top right of the page. This will create the subroutine that is called when you click the 'Edit' button on the datagrid.

4. You need to do this for the 'Update Command' as well. In this sub (which is for the 'Update' button) you'll need to add code to set the new values in the dataset and then update the dataset and re-bind the datagrid.

5. You should also create a subroutine for the cancel button.

The code for the edit button is something like:

Datagrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind

The code for the cancel button is something like:

DataGrid1.EditItemIndex = -1
DataGrid1.DataBind

hope that gives you something to work with

  • 0

I tried using the wizard, but it doesn't work for MYSQL databases (I can't afford SQL server). I found the following link http://msdn.microsoft.com/library/default....pterDataSet.asp and tried to adapt it to mysql, but I can't get it to work. Here is my code:

Protected Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click

myDataSet.AcceptChanges() 'when I don't have this, it throws a system error with no description

darAdapter.UpdateCommand = New MySQLCommand("UPDATE RequestedInventoryItems SET Quantity = @Quantity" & _

"WHERE ID = @ID", conMysql) 'conMysql is the MySQLConnection

darAdapter.UpdateCommand.Parameters.Add("@QuantityMyMySQLDbType.Int24, "Quantity")

Dim workParm As MySQLParameter = darAdapter.UpdateCommand.Parameters.Add("@IDMyMySQLDbType.Int24)

workParm.SourceColumn = "ID"

workParm.SourceVersion = DataRowVersion.Original

darAdapter.Update(myDataSet.Tables("Inventory"))

End Sub

PLEASE HELP! :wacko:

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.