xsharp.eu • Data relation issue - SOLVED
Page 1 of 1

Data relation issue - SOLVED

Posted: Tue Dec 27, 2022 10:25 am
by lumberjack
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?

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
Thx in advance,

Data relation issue

Posted: Tue Dec 27, 2022 10:39 am
by ic2
Hello Johan,

I am not using this so what I write here probably doesn't make sense, but if I look into the documentation below I'd say they assign values via fields, not directly like you do.

https://learn.microsoft.com/en-us/dotne ... ew=net-7.0

Dick

Data relation issue

Posted: Tue Dec 27, 2022 11:28 am
by TerryB1
Hello Johan

I cannot pretend I understand what your code is doing, but is it possible you are getting something that is zero based conflicting with something one based?

Terry

Data relation issue

Posted: Tue Dec 27, 2022 11:55 am
by lumberjack
Hi Terry,

Nope always work with 0 based.

I just can't understand why the Databinding complains it does not find the relationship "cust2sales"...

Data relation issue

Posted: Tue Dec 27, 2022 12:09 pm
by lumberjack
Terry,
Terry post=24882 userid=4511 wrote:Hello Johan

I cannot pretend I understand what your code is doing, but is it possible you are getting something that is zero based conflicting with something one based?

Terry
Here is an example of what I am trying to do:
LINK

Data relation issue

Posted: Tue Dec 27, 2022 2:56 pm
by TerryB1
Hi Johan
Thanks for link.
Not had time to fully understand it but get the gist. So this is just a further total guess.

You have the following lines in your code::

VAR oDR := System.Data.DataRelation{"cust2sales", ;
oDS:Tables["customer"]:Columns["customer"],;
oDS:Tables["transaction"]:Columns["dt_account"]}

I wonder if this should be more along the lines of:

VAR oDR := System.Data.DataRelation{"SOMETHING ELSE", ;
oDS:Tables["customer"]:Columns["customer"],;
oDS:Tables["customer"]:Columns["cust2Sales"],;
oDS:Tables["transaction"]:Columns["dt_account"]}

As I said this is a total guess,

Terry

Data relation issue

Posted: Tue Dec 27, 2022 6:25 pm
by lumberjack
Hi Terry,

The cust2sales is not a datacolumn it is merely the name of the relationship.

Data relation issue

Posted: Tue Dec 27, 2022 7:22 pm
by FFF
Johan,
like Dick, i know nothing ;-)
but i read this in DataGridView:Datamember help:
"However, if this DataSet contains multiple tables, you must set this property to the name of one of the tables."
?

Data relation issue - SOLVED

Posted: Wed Dec 28, 2022 12:21 pm
by lumberjack
Hi All,

Well in the end solved the issue using some common sense....

All the MS examples shows a oBS1, oBS2 for the datagridviews of the master and detail....

I merely attached oBS1 to both datagridviews and voila all well.
Thanks for your interaction.

Regards,