Data relation issue - SOLVED
Posted: Tue Dec 27, 2022 10:25 am
Hi all,
I have the following issue, the following code compiles but generate an error that the cust2sales datamember does not exist. Can anyone see where I am making a mistake?
Thx in advance,
I have the following issue, the following code compiles but generate an error that the cust2sales datamember does not exist. Can anyone see where I am making a mistake?
Code: Select all
PROTECTED METHOD Initialize() AS VOID
LOCAL oDT1, oDT2 AS DataTable
SELF:oButton3:Click += Button3Click
SELF:oIni := jhnIniFile{"BosPubSePush.exe.ini"}
SELF:oDS := System.Data.DataSet{"sales"}
oDT1 := DataTable{"customer"}
oDT1:Columns:Add("customer", typeof(System.String))
FOREACH cItem AS STRING IN oIni:GetItemNames("customer")
VAR oNewR := oDT1:NewRow()
oNewR["customer"] := cItem
oDT1:Rows:Add(oNewR)
NEXT
oDS:Tables:Add(oDT1)
oDT2 := DataTable{"transaction"}
oDT2:Columns:Add("txn_dt", typeof(System.String))
oDT2:Columns:Add("dt_account", typeof(System.String))
oDT2:Columns:Add("ct_account", typeof(System.String))
oDT2:Columns:Add("quantity", typeof(System.Int32))
oDT2:Columns:Add("amount", typeof(System.Int32))
FOREACH cItem AS STRING IN oIni:GetItemNames("transaction")
VAR cSub := oIni:GetString("transaction", cItem)
VAR cols := cSub.Split(";":ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
VAR oNR := oDT2:NewRow()
oNR["txn_dt"] := cItem
FOREACH kvp AS STRING IN cols
VAR col := kvp.Split(":":ToCharArray())
IF col[0]:Contains("account")
oNR[col[0]] := col[1]
ELSE
oNR[col[0]] := Convert.ToInt32(col[1])
ENDIF
NEXT
oDT2:Rows:Add(oNR)
NEXT
oDS:Tables:Add(oDT2)
VAR oDR := System.Data.DataRelation{"cust2sales", ;
oDS:Tables["customer"]:Columns["customer"],;
oDS:Tables["transaction"]:Columns["dt_account"]}
oDS:Relations:Add(oDR)
VAR oBS1 := System.Windows.Forms.BindingSource{}
oBS1:DataSource := oDS
oBS1:DataMember := "customer"
VAR oBS2 := System.Windows.Forms.BindingSource{}
oBS2:DataSource := oDS
// oBS2:DataMember := "cust2sales"
// VAR oBS := System.Windows.Forms.BindingSource{oDS, oDS:Tables["customer"]}
// oDS:Relations:Add(oDR)
SELF:oDataGridView1:DataSource := oBS1
// SELF:oDataGridView1:DataMember := "customer"
SELF:oDataGridView2:DataSource := oBS2
SELF:oDataGridView2:DataMember := "cust2sales" // ****************This line produce the error*******************
SELF:oDataGridView1:Columns["customer"]:Width := 200
RETURN