Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Data relation issue 27 Dec 2022 11:25 #24879

  • lumberjack
  • lumberjack's Avatar
  • Topic Author


  • Posts: 720
  • 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?
    	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,
    ______________________
    Johan Nel
    Boshof, South Africa

    Please Log in or Create an account to join the conversation.

    Last edit: by lumberjack. Reason: Reformat code section

    Data relation issue 27 Dec 2022 11:39 #24881

    • ic2
    • ic2's Avatar


  • Posts: 1608
  • 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.

    learn.microsoft.com/en-us/dotnet/api/sys...tribute?view=net-7.0

    Dick

    Please Log in or Create an account to join the conversation.

    Data relation issue 27 Dec 2022 12:28 #24882

    • Terry
    • Terry's Avatar


  • Posts: 297
  • 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

    Please Log in or Create an account to join the conversation.

    Data relation issue 27 Dec 2022 12:55 #24883

    • lumberjack
    • lumberjack's Avatar
    • Topic Author


  • Posts: 720
  • Hi Terry,

    Nope always work with 0 based.

    I just can't understand why the Databinding complains it does not find the relationship "cust2sales"...
    ______________________
    Johan Nel
    Boshof, South Africa

    Please Log in or Create an account to join the conversation.

    Data relation issue 27 Dec 2022 13:09 #24884

    • lumberjack
    • lumberjack's Avatar
    • Topic Author


  • Posts: 720
  • Terry,

    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
    ______________________
    Johan Nel
    Boshof, South Africa

    Please Log in or Create an account to join the conversation.

    Data relation issue 27 Dec 2022 15:56 #24885

    • Terry
    • Terry's Avatar


  • Posts: 297
  • 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

    Please Log in or Create an account to join the conversation.

    Data relation issue 27 Dec 2022 19:25 #24888

    • lumberjack
    • lumberjack's Avatar
    • Topic Author


  • Posts: 720
  • Hi Terry,

    The cust2sales is not a datacolumn it is merely the name of the relationship.
    ______________________
    Johan Nel
    Boshof, South Africa

    Please Log in or Create an account to join the conversation.

    Data relation issue 27 Dec 2022 20:22 #24889

    • FFF
    • FFF's Avatar


  • Posts: 1398
  • 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."
    ?
    Regards
    Karl (X# 2.14.0.4; Xide 1.33; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    Last edit: by FFF.

    Data relation issue - SOLVED 28 Dec 2022 13:21 #24894

    • lumberjack
    • lumberjack's Avatar
    • Topic Author


  • Posts: 720
  • 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,
    ______________________
    Johan Nel
    Boshof, South Africa

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1