Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Master/Child DataGrids... HELP! :)
Message
From
24/04/2004 18:48:22
 
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
00897937
Message ID:
00897956
Views:
12
There aren't actually orphans in the tables. I was just putting together a SELECT that selcted just a few of the parent records into the DataSet based on user input, but I was selecting all the child records into the DataSet simply because the SQL to select the child records based on the same user input would have been more complex. I've changed it now, though, to pull the child records based on the same criteria as the parents. So that particular issue is moot now. Nothing like combating lazyness and quirky code at the same time. :)

Here's the code I'm working with. I didn't write this, I inherited it and am trying to get it cleaned up and working by tonight. Don't ya envy me? ;)

Private Sub frmClient_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
load_grids()
format_grids()
End Sub

Sub load_grids()
Master_SQL = String.Format( _
"SELECT h.*, LEFT(h.ord_dte,8) as OrderDate, a.supp_nam " & _
" FROM qn_head h LEFT OUTER JOIN sup12004 a ON h.ord_supp = a.supp_cod " & _
" WHERE LEFT(ord_dte,8) >= '{0:yyyyMMdd}' " & _
" AND LEFT(ord_dte,8) <= '{1:yyyyMMdd}' ", _
dtpFromDate.Value, dtpToDate.Value)
Detail_SQL = String.Format( _
"SELECT ord_cod, itm_cod as 'Item Code', itm_bar, itm_nam as 'Item Name', itm_fam, itm_cat As 'Item Category', itm_mrq, " & _
" itm_mad, itm_lab, itm_dte, itm_min, itm_cur, itm_last, itm_prccr, " & _
" itm_prcll, itm_prcus, itm_cstcr, itm_cstll, itm_cstus, itm_locat, " & _
" itm_indic, itm_qty, itm_balqt, itm_prcqt, itm_salqt, itm_divqt, " & _
" itm_qtprc, itm_qtsal, itm_qtdiv, itm_qtrti, itm_qtrtp, itm_para, " & _
" itm_cons, itm_cnss, itm_dng1, itm_dng2, itm_dng3, itm_dng4, " & _
" itm_dng5, itm_dng6, itm_dng7, itm_dng8, itm_dng9, itm_dng10, " & _
" itm_all, itm_oth, itm_origc, itm_supp, itm_mrg, itm_change, " & _
" itm_oprccr, itm_oprcll, itm_oprcus, itm_act1, itm_act2, itm_act3, " & _
" itm_act4, itm_act5, itm_act6, itm_act7, itm_dos1, itm_dos2, " & _
" itm_dos3, itm_dos4, itm_dos5, itm_dos6, itm_dos7, itm_pres, " & _
" itm_cla, itm_soft, itm_1, itm_2, itm_purch, itm_print, itm_dos, " & _
" itm_clrpie, itm_clrbox, itm_psycho, itm_tva, itm_disc, armyprice, " & _
" itm_active, itm_max, itm_rl, itm_rq, itm_toord, itm_orderd, " & _
" itm_pack, qn, qn_sync, qn_sync_dt, qty_ord As 'Quantity Ordered', qty_rece, qty_offer, " & _
" ord_sent, sent_date As 'Sent To Server', date_stamp, rcv_date As 'Received From Server', owner " & _
" FROM qn_dtl " & _
" WHERE ord_cod IN " & _
" (SELECT ord_cod " & _
" FROM qn_head " & _
" WHERE LEFT(ord_dte,8) >= '{0:yyyyMMdd}' " & _
" AND LEFT(ord_dte,8) <= '{1:yyyyMMdd}' ", _
dtpFromDate.Value, dtpToDate.Value)

'
Select Case cbxStatus.Text.ToUpper
Case "PENDING"
Master_SQL &= " AND ord_sent = .F. "
Detail_SQL &= " AND ord_sent = .F. "
Case "SENT"
Master_SQL &= " AND ord_sent = .T. "
Detail_SQL &= " AND ord_sent = .T. "
End Select
If cbxAgent.SelectedValue > 0 Then
Master_SQL &= String.Format(" AND ord_supp={0} ", cbxAgent.SelectedValue)
Detail_SQL &= String.Format(" AND ord_supp={0} ", cbxAgent.SelectedValue)
End If
Detail_SQL &= ")"

Try
Load_OLE_DataGrid(DBF_Con, Master_SQL, dtgOrders, Detail_SQL, dtgDetails, "ord_cod")
Catch ex As Exception
MessageBox.Show("An error has occurred: " & ex.Message)
End Try
End Sub

Sub format_grids()
With Me.dtgOrders
With .TableStyles("Table1")
.AlternatingBackColor = System.Drawing.Color.LightGray
.BackColor = System.Drawing.Color.Gainsboro
.ForeColor = System.Drawing.Color.Black
.GridLineColor = System.Drawing.Color.DimGray
.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None
.HeaderBackColor = System.Drawing.Color.MidnightBlue
.HeaderFont = New System.Drawing.Font("Tahoma", 8.0!, System.Drawing.FontStyle.Bold)
.HeaderForeColor = System.Drawing.Color.White
.LinkColor = System.Drawing.Color.MidnightBlue
.SelectionBackColor = System.Drawing.Color.CadetBlue
.SelectionForeColor = System.Drawing.Color.White
.RowHeadersVisible = False
End With
.BackgroundColor = System.Drawing.Color.Silver
.BorderStyle = System.Windows.Forms.BorderStyle.None
.CaptionBackColor = System.Drawing.Color.LightSteelBlue
.CaptionForeColor = System.Drawing.Color.MidnightBlue
.CaptionVisible = False
.FlatMode = True
.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
End With

With Me.dtgDetails
.AlternatingBackColor = System.Drawing.Color.LightGray
.AlternatingBackColor = System.Drawing.Color.LightGray
.BackColor = System.Drawing.Color.Gainsboro
.BackgroundColor = System.Drawing.Color.Silver
.BorderStyle = System.Windows.Forms.BorderStyle.None
.CaptionBackColor = System.Drawing.Color.LightSteelBlue
.CaptionForeColor = System.Drawing.Color.MidnightBlue
.CaptionVisible = False
.FlatMode = True
.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
.ForeColor = System.Drawing.Color.Black
.GridLineColor = System.Drawing.Color.DimGray
.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None
.HeaderBackColor = System.Drawing.Color.MidnightBlue
.HeaderFont = New System.Drawing.Font("Tahoma", 8.0!, System.Drawing.FontStyle.Bold)
.HeaderForeColor = System.Drawing.Color.White
.LinkColor = System.Drawing.Color.MidnightBlue
.SelectionBackColor = System.Drawing.Color.CadetBlue
.SelectionForeColor = System.Drawing.Color.White
.RowHeadersVisible = False
End With

End Sub

Public Overloads Sub Load_OLE_DataGrid(ByVal ConnectionString As String, _
ByVal SqlStatement1 As String, _
ByRef DataGrid1 As DataGrid, _
ByVal SqlStatement2 As String, _
ByRef DataGrid2 As DataGrid, _
ByVal RelationColumn As String)
Dim objDataSet As New DataSet
Dim objSqlDataAdapter1 As OleDbDataAdapter
Dim objSqlDataAdapter2 As OleDbDataAdapter
Try
' Create the Master DataAdapter object based on the specified
' database connection string and SQL statement.
objSqlDataAdapter1 = New OleDbDataAdapter(SqlStatement1, ConnectionString)

' Fill the dataset from the Master DataAdapter object.
If objSqlDataAdapter1.Fill(objDataSet, "Table1") = 0 Then
DataGrid1.DataSource = Nothing
DataGrid2.DataSource = Nothing
Else

' Create the Detail DataAdapter object based on the specified
' database connection string and SQL statement.
objSqlDataAdapter2 = New OleDbDataAdapter(SqlStatement2, ConnectionString)

' Fill the dataset from the Detail DataAdapter object.
If objSqlDataAdapter2.Fill(objDataSet, "Table2") = 0 Then
' Specify the DataSource for the Master DataGrid.
DataGrid1.SetDataBinding(objDataSet, "Table1")
' No Details.
DataGrid2.DataSource = Nothing
Else

' Create a Data Relation for the Master/Detail tables based
' on the RelationColumn specified.
objDataSet.Relations.Add("TableRelation", _
objDataSet.Tables("Table1").Columns(RelationColumn), _
objDataSet.Tables("Table2").Columns(RelationColumn))

' Specify the DataSource for the Master DataGrid.
DataGrid1.SetDataBinding(objDataSet, "Table1")
'SizeColumnsToContent(DataGrid1, "Table1", objDataSet.Tables("Table1").Rows.Count)

' Specify the DataSource for the Detail DataGrid.
DataGrid2.SetDataBinding(objDataSet, "Table1.TableRelation")
'SizeColumnsToContent(DataGrid2, "Table2", objDataSet.Tables("Table2").Rows.Count)
End If
End If
' Make the Master/Details Data Grids read-only.
DataGrid1.ReadOnly = True
DataGrid2.ReadOnly = True
Catch ex As Exception
Throw ex
Finally
' Release our objects.
objSqlDataAdapter1 = Nothing
objSqlDataAdapter2 = Nothing
objDataSet = Nothing
End Try
End Sub

-----
Lee Perkins
-----
Lee Perkins
TigerBase Technologies

"Lee is one that would plug his brain into the internet, if he could, and STILL scream for more" - Very good friend of Lee's
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform