Delete Datagrid from Multiple Sources (VB)

M

Motley Drew

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
'******************************************************
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top