The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
Error Bounding Fields
Posted: 21 Oct 08 3:42 PM
|
Hi everyone I have a PickList Field related to a Entity Field(Siccode) and Edit Text Box Related to another Entity Field (Industry) So i need to select a PickList value and when it change I need to Populate Entity Field with an Industry that matches with SICCODEID selected
That's my Code for Lookup's result:
if (lueSICCode.LookupResultValue.ToString() != "") { //String Builder System.Text.StringBuilder sb = new StringBuilder(); //Sentencia SQL sb.Append("SELECT SICCODE.INDUSTRY AS INDUSTRY "); sb.Append("FROM SICCODE "); sb.Append("WHERE SICCODE.SICCODE = '" + lueSICCode.LookupResultValue.ToString() + "'");
//Conexion de Sage Sage.Platform.Data.IDataService data = Sage.Platform.Application.ApplicationContext.Current.Services.Get(); System.Data.OleDb.OleDbConnection objConnection = (System.Data.OleDb.OleDbConnection)data.GetConnection(); //Command System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand(sb.ToString(), objConnection); if (objConnection != null) { if (cmd.Connection.State != System.Data.ConnectionState.Open) { try { // Datareader System.Data.OleDb.OleDbDataReader dr; cmd.Connection.Open(); dr = cmd.ExecuteReader();
if (dr.HasRows) { while (dr.Read()) { edtIndustry.Text = dr["INDUSTRY"].ToString(); } }
} catch { } finally { cmd.Connection.Close(); cmd.Connection.Dispose(); } } } }
But I've been debbuging my Code and I've got values but i don't know why Field is never populated.
I just get values when i remove Link with Entity Field Industry.
Does someone know what's happening? |
|
|
|
Re: Error Bounding Fields
Posted: 22 Oct 08 12:23 AM
|
So your edtIndustry.Text = dr["INDUSTRY"].ToString(); is causing a problem?
What it you try to set to to a static value to that like edtIndustry.Text = "My Test"; Like without any other code... What happens?
I imagine that is going to work? With that being said is anything else 'touching' that object? What f you create a different text object for edtIndustry on you form and try to populate that from your code?
You might also try to drop into Visual Studio to get some more information during debug...
--Ken-- |
|
|
|
Re: Error Bounding Fields
Posted: 22 Oct 08 3:17 AM
|
Is the edtIndustry field bound to the Account.Industry property? It should be..
If so, populate the property of the entity not the control...
So replace the relavant part with:
// Datareader System.Data.OleDb.OleDbDataReader dr; cmd.Connection.Open(); dr = cmd.ExecuteReader();
try { // Datareader System.Data.OleDb.OleDbDataReader dr; cmd.Connection.Open(); dr = cmd.ExecuteReader();
//NH
Sage.Entity.Interfaces.Iaccount acc = this.BindingSource.Current as Sage.Entity.Interfaces.IAccount;
if (dr.HasRows) { while (dr.Read()) { //edtIndustry.Text = dr["INDUSTRY"].ToString(); -- DONT USE. acc.Industry = dr["INDUSTRY"].ToString(); } }
} catch { } finally { cmd.Connection.Close(); cmd.Connection.Dispose(); } }
|
|
|
|
Re: Error Bounding Fields
Posted: 22 Oct 08 3:19 AM
|
It sounds like your edit field is bound, so as soon as you set the text of the control the binding is overriding it with a blank values form the DB.
Is the edtIndustry field bound to the Account.Industry property? It should be..
If so, populate the property of the entity NOT the control...
So replace the relevant part with:
// Datareader System.Data.OleDb.OleDbDataReader dr; cmd.Connection.Open(); dr = cmd.ExecuteReader();
try { // Datareader System.Data.OleDb.OleDbDataReader dr; cmd.Connection.Open(); dr = cmd.ExecuteReader();
//NH
Sage.Entity.Interfaces.IAccount acc = this.BindingSource.Current as Sage.Entity.Interfaces.IAccount;
if (dr.HasRows) { while (dr.Read()) { //edtIndustry.Text = dr["INDUSTRY"].ToString(); -- DONT USE. acc.Industry = dr["INDUSTRY"].ToString(); //acc.Save(); - optional whether you want to save the record here, or wait until the user clicks save,... } }
} catch { } finally { cmd.Connection.Close(); cmd.Connection.Dispose(); } }
Cheers, Nick
|
|
|
|
Re: Error Bounding Fields
Posted: 22 Oct 08 9:19 AM
|
That's really good, I missed bound Entity, I had bounded only the Control not the Entity, Thank You Misael. |
|
|
|