Try
With myCMD
.Connection = myConn
.CommandText = "SELECT * FROM TAG_InspectionCategories "
.CommandType = CommandType.Text
End With
myDA.SelectCommand = myCMD
myConn.Open()
myDA.Fill(dsCategories, "Categories")
gvCategories.DataSource = dsCategories.Tables(0)
gvCategories.DataBind()
myConn.Close()
Catch ex As Exception
If myConn.State = ConnectionState.Open Then
myConn.Close()
End If
End Try
dsCategories.Tables(0).Rows(e.RowIndex).Delete()
dsCategories.Tables(0).Rows(e.RowIndex).AcceptChanges()
gvCategories.DataSource = dsCategories.Tables(0)
gvCategories.DataBind()
Dim strQuery as String
'Assign the query that orginally fills the datatable
strQuery = "SELECT * FROM TAG_InspectionCategories"
'Create the DataAdapter object
Dim daAdapter As New SqlDataAdapter(strQuery, conConnection)
'this will create all the UPDATE statements for you
Dim dcbCommand As New SqlCommandBuilder(daAdapter)
'this will update your Database
daAdapter.Update(dt)
daAdapter.Dispose()
Private Sub gvCategories_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvCategories.RowUpdating
Dim dt As DataTable = dsCategories.Tables(0)
'Update the values.
Dim row = gvCategories.Rows(e.RowIndex)
dt.Rows(row.DataItemIndex)("Short_Name") = (CType((row.Cells(2).Controls(0)), TextBox)).Text 'Assuming you have a Textbox in the column
dt.Rows(row.DataItemIndex)("Long_Name") = (CType((row.Cells(3).Controls(0)), TextBox)).Text 'Assuming you have a Textbox in the column
dt.Rows(row.DataItemIndex)("Active") = (CType((row.Cells(4).Controls(0)), CheckBox)).Checked 'Assuming you have a checkbox in the column
'Reset the edit index.
gvCategories.EditIndex = -1
'Bind data to the GridView control.
gvCategories.DataSource = dt
gvCategories.DataBind()
Dim strQuery As String
myConn.ConnectionString = ConStr
'Assign the query that orginally fills the datatable
strQuery = "SELECT * FROM TAG_InspectionCategories"
'Create the DataAdapter object
Dim daAdapter As New SqlDataAdapter(strQuery, myconn)
'this will create all the UPDATE statements for you
Dim dcbCommand As New SqlCommandBuilder(daAdapter)
Try
'this will update your Database
myConn.Open()
daAdapter.Update(dt)
daAdapter.Dispose()
myConn.Close()
Catch ex As Exception
End Try
End Sub