Company Adapter not updating

Hello, I am trying to update a field in the Company table from a Customization in Receipt Entry. I have done this with other adapters but having trouble with this one using code Ive found on this forum.

But with the company adapater for some reason when I call GetCompanyByID it doesnt update the adapter object so I can access the rows I want to update.

CompanyAdapter companyAdaptr = new CompanyAdapter(this.oTrans);
companyAdaptr.BOConnect();
companyAdaptr.GetCompanyByID("VTLB");		
MessageBox.Show(companyAdaptr.CompanyData.Company.Rows[0]["LBAutoPackInt_c"].ToString());  // says there is no data a row 0

But if I return the GetCompanyByID to a DataSet variable I can access what I need. But the update function doesnt work

CompanyAdapter companyAdaptr = new CompanyAdapter(this.oTrans);
companyAdaptr.BOConnect();
DataSet CompanyDataSet = companyAdaptr.GetCompanyByID("VTLB");
MessageBox.Show(CompanyDataSet.Tables["Company"].Rows[0]["LBAutoPackInt_c"].ToString) // displays the information I need

Ultimately im trying to increment a field in the company table from a customization from Receipt Entry but the update doesnt happen. I was thinking it has to do with me updating the DataSet variable instead of the adapter object. Cant figure out why I can get the info directly from the adapter. Any Idea on why that is?

Full Code trying to update

CompanyAdapter companyAdaptr = new CompanyAdapter(this.oTrans);
companyAdaptr.BOConnect();
DataSet CompanyDataSet = companyAdaptr.GetCompanyByID("VTLB");
	
int PackSlipCounter = (int) CompanyDataSet.Tables["Company"].Rows[0]["LBAutoPackInt_c"]; 
PackSlipCounter += 1;
packslip_txt.Value = "LB" + PackSlipCounter.ToString();
packslip_txt.Focus();
	
CompanyDataSet.Tables["Company"].Rows[0]["LBAutoPackInt_c"] = PackSlipCounter;
CompanyDataSet.Tables["Company"].Rows[0]["RowMod"] = "U";

companyAdaptr.Update();
companyAdaptr.Dispose();

Copy your row into the adapter dataset.

Ah, thats a good idea. thanks for looking at this I tried this:

companyAdaptr.CompanyData.Company.Rows[0] = CompanyDataSet.Tables["Company"].Rows[0];

But get this error:

Property or indexer ‘System.Data.DataRowCollection.this[int]’ cannot be assigned to – it is read only

Is there another way? I have not done something like this before.

ok, this worked. thanks for the help

// connect to company adapter  
CompanyAdapter companyAdaptr = new CompanyAdapter(this.oTrans);
companyAdaptr.BOConnect();

// Get Last Pack Slip Number
DataSet CompanyDataSet = companyAdaptr.GetCompanyByID("VTLB");
int PackSlipCounter = (int) CompanyDataSet.Tables["Company"].Rows[0]["LBAutoPackInt_c"]; 
	
//Update Pack Slip
PackSlipCounter += 1;
packslip_txt.Value = "LB" + PackSlipCounter.ToString();
packslip_txt.Focus();
	
// update company dataset 
CompanyDataSet.Tables["Company"].Rows[0]["LBAutoPackInt_c"] = PackSlipCounter;
CompanyDataSet.Tables["Company"].Rows[0]["RowMod"] = "U";
	
//import data back into company adapter for update
foreach(DataTable AdapterTable in companyAdaptr.CompanyData.Tables)
    {
	foreach(DataTable MyTable in CompanyDataSet.Tables)
	{
		if (AdapterTable.TableName == MyTable.TableName)
		{
			foreach(DataRow row in MyTable.Rows)
			{
				AdapterTable.ImportRow(row);
			}
		}
	}       	
     }
	
// update company table
companyAdaptr.Update();
companyAdaptr.Dispose();


1 Like