Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand '---new variables to hold the data from the row being edited Dim NewNeed As String Dim NewYear As Short Dim NewCategory As Short Dim NewQty As Short Dim NewCost As Decimal Dim NewPriority As Short Dim NewStatus As Short Dim NewJustification As String '---make sure we catch any errors while opening the DB or writing to it. Try '---we need to take data from the textboxes inside the controls collection for the row. ' So we convert the data in the cell to a TextBox web control and then take its text property! ' '---for template columns, we must create an object to match the type created because the ' textbox used for editing is created at run-time during edit mode. ' So we create a scratch object of the correct type, find the new control during edit, then ' set the parameter property to the property of the scratch object. Dim temp As New TextBox temp = e.Item.FindControl("txtNeed2Edit") NewNeed = temp.Text Dim temp2 As New DropDownList temp2 = e.Item.FindControl("lbYear") NewYear = temp2.SelectedValue Dim temp3 As New DropDownList temp3 = e.Item.FindControl("lbCategory") NewCategory = temp3.SelectedValue Dim temp4 As New DropDownList temp4 = e.Item.FindControl("lbStatus") NewStatus = temp4.SelectedValue NewQty = CType(e.Item.Cells(4).Controls(0), TextBox).Text NewCost = CType(e.Item.Cells(5).Controls(0), TextBox).Text NewPriority = CType(e.Item.Cells(6).Controls(0), TextBox).Text NewJustification = CType(e.Item.Cells(8).Controls(0), TextBox).Text Rec2Edit = e.Item.Cells(9).Text 'this is not inside a textbox(read only) so we just grab it '---now let's update the database record. We are keying off of RecNum in the Needs table as the primary key Dim strConnection As String Dim strSql As String Dim strMyPath As String Dim objConn As OleDbConnection Dim objCmd As OleDbCommand '---define the local path and initialize connection object strMyPath = Server.MapPath("\emp\fpdb\emp-02.mdb") 'server path strConnection = "Provider =Microsoft.Jet.OLEDB.4.0; Data Source=" & strMyPath objConn = New OleDbConnection(strConnection) strSql = "UPDATE NEEDS SET Description=@Descrip, YrNeeded=@Year, Category=@Category, " & _ "Quantity=@Qty, Cost=@NewCost, Priority=@Priority, StatusCode=@Status, Justification=@Justify WHERE Needs.RecNum =@RecNum" '---PARAMETERS SECTION ' Create a new cmd object to handle our parameters and build the values for our fields. objCmd = New OleDbCommand(strSql, objConn) '---THESE MUST BE IN THE SAME ORDER AS THEY ARE DEFINED IN THE SQL STRING ABOVE objCmd.Parameters.Add(New OleDbParameter("@Descrip", NewNeed)) objCmd.Parameters.Add(New OleDbParameter("@Year", NewYear)) objCmd.Parameters.Add(New OleDbParameter("@Category", NewCategory)) objCmd.Parameters.Add(New OleDbParameter("@Qty", NewQty)) objCmd.Parameters.Add(New OleDbParameter("@NewCost", NewCost)) objCmd.Parameters.Add(New OleDbParameter("@Priority", NewPriority)) objCmd.Parameters.Add(New OleDbParameter("@Status", NewStatus)) objCmd.Parameters.Add(New OleDbParameter("@Justify", NewJustification)) objCmd.Parameters.Add(New OleDbParameter("@RecNum", Rec2Edit)) 'make it so! objConn.Open() 'open the actual connection to the db objCmd.ExecuteNonQuery() objConn.Close() DataGrid1.EditItemIndex = -1 Catch MyError As Exception 'do not have to Dim MyError in this case. This catches any error lblError.Text = "An error occured while attempting to update this record. " & _ " Make sure you input the correct data. For example, do not type a letter in a column that accepts only numbers. " & _ " Please exit to the main menu and again." lblError.Visible = True DataGrid1.Visible = False End Try DataGrid1.EditItemIndex = -1 BindNeedsGrid() End Sub