Retrieve Data from database table to Non-Database EpiDataView

Hi, Recently I’m implementing additional field which is manufacturer part number. At first everything’s fine, I can create a UD field in Part_UD after that save some value to it and retrieved it on Job Entry using this:


image

Blockquote
private void QuoteDtl_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
// ** Argument Properties and Uses **
// args.Row[“FieldName”]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code
switch (args.Column.ColumnName)
{
case “PartNum”:
PartAdapter adpPart = new PartAdapter(this.oTrans);
adpPart.BOConnect();
adpPart.GetByID(Convert.ToString(args.ProposedValue));

        string MfrPartNum_c = Convert.ToString(adpPart.PartData.Tables["Part"].Rows[0]["MfrPartNum_c"]);
		string PartBrand_c = Convert.ToString(adpPart.PartData.Tables["Part"].Rows[0]["PartBrand_c"]);			
												
        args.Row["MfrPartNum_c"] = MfrPartNum_c;
		args.Row["PartBrand_c"] = PartBrand_c;			
        adpPart.Dispose();		
	break;
}

}

Blockquote
When face the obstacles when comes to a form that’s build up by non-database table which is issues material form.

  1. So first think I did is to create a field for binding purposes
    ((EpiDataView)oTrans.EpiDataViews[“Select”]).dataView.Table.Columns.Add(“MfrPartNum_c”, typeof(String));

After I did that, I went to Form Event Wizard to generate a AfterFieldChange event
private void SelectedJobAsmbl_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
// ** Argument Properties and Uses **
// args.Row[“FieldName”]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code

		switch (args.Column.ColumnName)
		{
			case "JobNum":


				EpiDataView edvSelect = (EpiDataView)oTrans.EpiDataViews["SelectedJobAsmbl"];
						
			if(edvSelect.dataView.Count > 0)
				{
				string partNum = Convert.ToString(edvIM.dataView[edvIM.Row]["PartNum"] );			              
	
					PartAdapter adpPart = new PartAdapter(this.oTrans);
					adpPart.BOConnect();					
					bool MorePages;
					String whereClause = "PartNum='"+partNum+"'";
					SearchOptions opts = new SearchOptions(SearchMode.AutoSearch);
					opts.NamedSearch.WhereClauses.Add("Part", whereClause);
					DataSet dsPart = adpPart.GetRows(opts, out MorePages);

			if(dsPart.Tables["Part"].Rows.Count>0)
					{
						  
			    	string MfrPartNum_c = Convert.ToString(adpPart.PartData.Tables["Part"].Rows[0]["MfrPartNum_c"]);
			
					edvSelect.dataView[edvSelect.Row]["MfrPartNum_c"] = MfrPartNum_c;
				
					}			
			       // adpPart.Dispose();

				//dvSelect.dataView[edvSelect.Row]["MfrPartNum_c"] = edvCallContextBpmData.dataView[edvCallContextBpmData.Row]["Character01"];
				}

				break;
		}

After that, when I try run, this error message prompted out,

Anyone has any idea on this?

Thank you!

Hey Guys, I’ve found the solution.
I will paste the code here incase any of u need help.

extern alias Erp_Adapters_Part;

extern alias Erp_Contracts_BO_IssueReturn;
extern alias Erp_Contracts_BO_JobEntry;
extern alias Erp_Contracts_BO_JobAsmSearch;
extern alias Erp_Contracts_BO_JobMtlSearch;

using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;

public class Script
{
// ** Wizard Insert Location - Do Not Remove ‘Begin/End Wizard Added Module Level Variables’ Comments! **
// Begin Wizard Added Module Level Variables **

private EpiDataView edvIM;
private EpiDataView edvCallContextBpmData;
private EpiDataView edvSelect;
// End Wizard Added Module Level Variables **

// Add Custom Module Level Variables Here **

public void InitializeCustomCode()
{
	// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
	// Begin Wizard Added Variable Initialization
	((EpiDataView)oTrans.EpiDataViews["Select"]).dataView.Table.Columns.Add("MfrPartNum_c", typeof(String));

	this.edvIM = ((EpiDataView)(this.oTrans.EpiDataViews["IM"]));

	this.edvCallContextBpmData = ((EpiDataView)(this.oTrans.EpiDataViews["CallContextBpmData"]));

	this.SelectedJobAsmbl_Column.ColumnChanged += new DataColumnChangeEventHandler(this.SelectedJobAsmbl_AfterFieldChange);
	

	this.edvSelect = ((EpiDataView)(this.oTrans.EpiDataViews["Select"]));
	

	// End Wizard Added Variable Initialization
	
	// Begin Wizard Added Custom Method Calls

	SetExtendedProperties();
	// End Wizard Added Custom Method Calls
}

public void DestroyCustomCode()
{
	// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
	// Begin Wizard Added Object Disposal

	
	this.edvIM = null;
	
	this.edvCallContextBpmData = null;
	
	
	
	this.SelectedJobAsmbl_Column.ColumnChanged -= new DataColumnChangeEventHandler(this.SelectedJobAsmbl_AfterFieldChange);
	
	
	
	this.edvSelect = null;


	// End Wizard Added Object Disposal

	// Begin Custom Code Disposal

	// End Custom Code Disposal
}

private void SetExtendedProperties()
{
	// Begin Wizard Added EpiDataView Initialization
	EpiDataView edvIM = ((EpiDataView)(this.oTrans.EpiDataViews["IM"]));
	// End Wizard Added EpiDataView Initialization

	// Begin Wizard Added Conditional Block
	if (edvIM.dataView.Table.Columns.Contains("TranDate"))
	{
		// Begin Wizard Added ExtendedProperty Settings: edvIM-TranDate
		edvIM.dataView.Table.Columns["TranDate"].ExtendedProperties["ReadOnly"] = true;
		// End Wizard Added ExtendedProperty Settings: edvIM-TranDate
	}
	// End Wizard Added Conditional Block
}

private void SelectedJobAsmbl_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
	{
		// ** Argument Properties and Uses **
		// args.Row["FieldName"]
		// args.Column, args.ProposedValue, args.Row
		// Add Event Handler Code

		switch (args.Column.ColumnName)
		{
			case "JobNum":
			if(edvSelect.dataView.Count > 0)
			{
				string partNum = Convert.ToString(edvSelect.dataView[edvSelect.Row]["PartNum"] );

					PartAdapter adpPart = new PartAdapter(this.oTrans);
					adpPart.BOConnect();
					bool MorePages;
					String whereClause = "PartNum='"+partNum+"'";
					SearchOptions opts = new SearchOptions(SearchMode.AutoSearch);
					opts.NamedSearch.WhereClauses.Add("Part", whereClause);
					DataSet dsPart = adpPart.GetRows(opts, out MorePages);

				if(dsPart.Tables["Part"].Rows.Count>0)
				{
					string MfrPartNum_c = Convert.ToString(dsPart.Tables["Part"].Rows[0]["MfrPartNum_c"]);
	
					edvSelect.dataView[edvSelect.Row].BeginEdit();	
					edvSelect.dataView[edvSelect.Row]["MfrPartNum_c"] = MfrPartNum_c;
					edvSelect.dataView[edvSelect.Row].EndEdit();

				}


  			 adpPart.Dispose();
			}
			break;
		}

		
	}

}