Hello All,
I need a delete and update vb codes to understand how the datakeys functions....
Thanks,
I need a delete and update vb codes to understand how the datakeys functions....
Thanks,
Dim key as String = Datagrid1.DataKeys(e.Item.ItemIndex)
StoryDA.SelectCommand.CommandText = "SELECT * FROM Story_Master WHERE SID=" & key
StoryDA.UpdateCommand = OleDbUpdateCommand1
Dim workParm As OleDbParameter = StoryDA.UpdateCommand.Parameters.Add(key, OleDbType.Integer)
workParm.SourceColumn = "SID"
workParm.SourceVersion = DataRowVersion.Original
StoryDA.Fill(StorySet)
Dim workrow As DataRow = StorySet.Story_Master.Rows(0)
workrow("Story_Section") = drplistSection.SelectedItem.ToString
Try
StoryDA.Update(StorySet)
Response.Redirect("Edit_Story.aspx?SID=" & Request.QueryString("SID") & "&Type=Updated")
Catch ex As Exception
lblErr.Text = ex.Message
End Try
Dim key As String = StoryDG.DataKeys(e.Item.ItemIndex).ToString()
Dim catDA As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM Story_Master WHERE SID =" & key, OleDbConnection1)
catDA.DeleteCommand = New OleDbCommand("DELETE FROM Story_Master WHERE SID = ?", OleDbConnection1)
Dim workParm As OleDbParameter = catDA.DeleteCommand.Parameters.Add(key, OleDbType.Integer)
workParm.SourceColumn = "SID"
workParm.SourceVersion = DataRowVersion.Original
Dim catDS As DataSet = New DataSet
catDA.Fill(catDS, "Story_Master")
Dim cRow As DataRow = catDS.Tables("Story_Master").Rows(0)
cRow.Delete()
Dim modRows() As DataRow = catDS.Tables("Story_Master").Select(Nothing, Nothing, DataViewRowState.Deleted)
Try
catDA.Update(modRows)
Catch ex As Exception
Response.Write(ex.Message)
End Try
Comment