A vb code shows the use of datakeys

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dianaj86
    New Member
    • Jan 2007
    • 11

    A vb code shows the use of datakeys

    Hello All,
    I need a delete and update vb codes to understand how the datakeys functions....
    Thanks,
  • jaketrimble
    New Member
    • Jan 2007
    • 14

    #2
    Originally posted by dianaj86
    Hello All,
    I need a delete and update vb codes to understand how the datakeys functions....
    Thanks,
    Update Example:
    Code:
    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
    Delete Example:
    Code:
    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
    Hope this helps, if you need explaining, just let me know

    Comment

    • dianaj86
      New Member
      • Jan 2007
      • 11

      #3
      Thanks for the reply Jaketrible...

      Comment

      Working...