Delete Datagrid from Multiple Sources (VB)

Discussion in 'ASP .Net Datagrid Control' started by Motley Drew, Feb 18, 2004.

  1. Motley Drew

    Motley Drew Guest

    I have been trying to figure this out forever. I have two tables that
    make up my datagrid. Table1 has 3 primary keys, table2 has one primary
    key. The primary key in table 2 joins with a primary key in table1 (I
    didn't design the back-end, just have to deal with it.)

    All I am trying to do is delete a row made up from values of both
    tables. I have deletes working for other tables.

    Anyone who can help me out with this has a free lunch coming. Code
    below.

    Thanks.
    -Motley Drew




    '******************************************************
    Public Sub Delete_Condition_Row(ByVal Sender As Object, ByVal E As
    DataGridCommandEventArgs)

    ' Retrieve the ID of the product to be deleted
    Dim strInterfaceId = DropDownInterfaceId.SelectedItem.Value
    Dim strConId As String = Trim(E.Item.Cells(2).Text)
    Dim strType As String = Trim(E.Item.Cells(3).Text)
    Dim strSQLQuery As String
    Dim objConnection As SqlConnection
    strSQLQuery = "exec sp_load_conditions '" &
    DropDownInterfaceId.SelectedItem.Value & "'"
    objConnection = New SqlConnection("Data Source=ocssap002.oc.intel.com;"
    _
    & "Initial Catalog=drew_tibco;User Id=sa;Password=xxxx;" _
    & "Connect Timeout=5;")

    dgConditionFull.EditItemIndex = -1

    ' Create and load a DataSet
    Dim adapter As New SqlDataAdapter(strSQLQuery, objConnection)
    Dim ds As New DataSet()
    adapter.Fill(ds, "tbl_gen_in_int_conds")
    adapter.Fill(ds, "tbl_gen_in_cond_defns")

    ' Mark the product as Deleted in the DataSet
    Dim tbl As DataTable = ds.Tables("tbl_gen_in_int_conds")
    Dim tbl2 As DataTable = ds.Tables("tbl_gen_in_cond_defns")

    Dim keys(3) As DataColumn
    keys(0) = tbl.Columns("INTERFACE_ID")
    keys(1) = tbl.Columns("COND_TYPE")
    keys(2) = tbl.Columns("CONDITION")
    tbl.PrimaryKey = keys

    Dim keyVals(2) As String
    keyVals(0) = strInterfaceId
    keyVals(1) = strType
    keyVals(2) = strConId

    Dim row As DataRow = tbl.Rows.Find(keyVals)
    row.Delete()

    ' Reconnect the DataSet and delete the row from the database
    '-----------------------------------------------------------
    ' Following section commented out for demonstration purposes
    Dim cb As New SqlCommandBuilder(adapter)
    Connect()
    adapter.Update(ds, "tbl_gen_in_int_conds")
    '-----------------------------------------------------------
    ' Display remaining rows in the DataGrid
    dgConditionFull.DataSource = ds.Tables("tbl_gen_in_int_conds")
    dgConditionFull.DataBind()

    'Declare data objects
    Dim objConnection3 As SqlConnection
    Dim objCommand3 As SqlCommand
    Dim objDataReader3 As SqlDataReader

    ' Build SQL query
    objConnection3 = New SqlConnection("Data Source=ocssap002.oc.intel.com;"
    _
    & "Initial Catalog=drew_tibco;User Id=sa;Password=xxxx;" _
    & "Connect Timeout=5;")
    strSQLQuery = "exec sp_load_conditions '" &
    DropDownInterfaceId.SelectedItem.Value & "'"

    ' Create a new command object that uses the connection
    ' and set the text of the command to be executed
    objCommand3 = New SqlCommand(strSQLQuery, objConnection3)
    objConnection3.Open()

    ' Get a new datareader from the command
    objDataReader3 =
    objCommand3.ExecuteReader(CommandBehavior.CloseConnection)

    'Got data... put it back in Condition grid
    dgConditionFull.DataSource = objDataReader3
    dgConditionFull.DataBind()

    End Sub
    '******************************************************


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Motley Drew, Feb 18, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hamed
    Replies:
    3
    Views:
    3,298
    Richard Grimes [MVP]
    Feb 15, 2004
  2. Salman Sheikh

    Address muxing from multiple sources

    Salman Sheikh, Aug 28, 2003, in forum: VHDL
    Replies:
    0
    Views:
    560
    Salman Sheikh
    Aug 28, 2003
  3. Henk De Denktenk
    Replies:
    6
    Views:
    660
  4. sudha
    Replies:
    0
    Views:
    591
    sudha
    Jan 3, 2005
  5. Fred Zolar
    Replies:
    0
    Views:
    205
    Fred Zolar
    Apr 1, 2004
Loading...

Share This Page