UserCode Adapter Update


(Ross Hughes) #1

I am trying to read the next number from the UserCode table, add 1 and then write it back for auto numbering. It is all working except it doesn’t write back. What else is needed to updated the usercode record?

private string getNextPartNum()
{
	string nextPartNum = String.Empty;
	bool morePages = false;
	UserCodesAdapter adpUserCodes = new UserCodesAdapter(oTrans);
	adpUserCodes.BOConnect();
	SearchOptions opts = new SearchOptions(SearchMode.AutoSearch);
	string whereClauseCodeTypeID = "CodeTypeID = 'AutoNumber'";
	string whereClauseCodeID = "CodeID = 'PartNum'";
	opts.NamedSearch.WhereClauses.Add("UDCodeType", whereClauseCodeTypeID);
	opts.NamedSearch.WhereClauses.Add("UDCodes", whereClauseCodeID);
	DataSet dsUserCodes = adpUserCodes.GetRows(opts, out morePages);
	if(dsUserCodes.Tables[0].Rows.Count > 0)
	{
		int nextPartNumber = Convert.ToInt32(dsUserCodes.Tables[1].Rows[0]["CodeDesc"].ToString()) + 1;
		dsUserCodes.Tables[1].Rows[0]["CodeDesc"] = nextPartNumber.ToString();
		//adpUserCodes.Update();
		EpiDataView edvDupPart = (EpiDataView)(oTrans.EpiDataViews["NoBoundField"]);
		edvDupPart.dataView[edvDupPart.Row]["DupPart"] = nextPartNumber;
	}
	adpUserCodes.Dispose();
	return nextPartNum;
}

Thanks!
Ross


(Theodore Koch) #2

Try this.

        int nextPartNumber = Convert.ToInt32(udAdapt.UserCodesData.UDCodes[0]["CodeDesc"]) + 1;
        udAdapt.UserCodesData.UDCodes[0]["CodeDesc"] = nextPartNumber.ToString();
        udAdapt.Update();

(Ross Hughes) #3

Thank you!

When I try it it tells me I have no rows at position 0.

image

Here is my updated code:

private string getNextPartNum()
{
	string nextPartNum = String.Empty;
	bool morePages = false;
	UserCodesAdapter adpUserCodes = new UserCodesAdapter(oTrans);
	adpUserCodes.BOConnect();
	SearchOptions opts = new SearchOptions(SearchMode.AutoSearch);
	string whereClauseCodeTypeID = "CodeTypeID = 'AutoNumber'";
	string whereClauseCodeID = "CodeID = 'PartNum'";
	opts.DataSetMode = DataSetMode.RowsDataSet;
	opts.NamedSearch.WhereClauses.Add("UDCodeType", whereClauseCodeTypeID);
	opts.NamedSearch.WhereClauses.Add("UDCodes", whereClauseCodeID);
	DataSet dsUserCodes = adpUserCodes.GetRows(opts, out morePages);
	//adpUserCodes.GetRows(opts, out morePages);
	if(dsUserCodes.Tables[0].Rows.Count > 0)
	{
		int nextPartNumber = Convert.ToInt32(adpUserCodes.UserCodesData.UDCodes[0]["CodeDesc"]) + 1;
		adpUserCodes.UserCodesData.UDCodes[0]["CodeDesc"] = nextPartNumber.ToString();
		adpUserCodes.Update();
		//MessageBox.Show(adpUserCodes.UserCodesData.UDCodes[0]["CodeDesc"].ToString());
		EpiDataView edvDupPart = (EpiDataView)(oTrans.EpiDataViews["NoBoundField"]);
		edvDupPart.dataView[edvDupPart.Row]["DupPart"] = nextPartNumber;
	}
	adpUserCodes.Dispose();
	return nextPartNum;
}

Thanks again for the response. I will keep working with it.

Ross


(Theodore Koch) #4

Use this to retrieve the desired records.

            string wc = string.Format("CodeTypeID='{0}' AND CodeID='{1}'", "AutoNumber", "PartNum");
            System.Collections.Hashtable wcs = new Hashtable(1);
            wcs.Add("UDCodes", wc);
            Ice.Lib.Searches.SearchOptions searchOpts = Ice.Lib.Searches.SearchOptions.CreateRuntimeSearch(wcs, Ice.Lib.Searches.DataSetMode.RowsDataSet);
            adpUserCodes.InvokeSearch(searchOpts);
            if (adpUserCodes.UserCodesData.UDCodeType.Count > 0)
            {

            }

(Ross Hughes) #5

Thanks, Theodore! I appreciate it. Working final version below:

private string getNextPartNum()
{
	string nextPartNum = String.Empty;
	bool morePages = false;
	UserCodesAdapter adpUserCodes = new UserCodesAdapter(oTrans);
	adpUserCodes.BOConnect();
	string wc = string.Format("CodeTypeID='{0}' AND CodeID='{1}'", "AutoNumber", "PartNum");
    System.Collections.Hashtable wcs = new Hashtable(1);
    wcs.Add("UDCodes", wc);
    Ice.Lib.Searches.SearchOptions searchOpts = Ice.Lib.Searches.SearchOptions.CreateRuntimeSearch(wcs, Ice.Lib.Searches.DataSetMode.RowsDataSet);
    adpUserCodes.InvokeSearch(searchOpts);
	if(adpUserCodes.UserCodesData.UDCodeType.Count > 0)
	{
		int nextPartNumber = Convert.ToInt32(adpUserCodes.UserCodesData.UDCodes[0]["CodeDesc"]) + 1;
		adpUserCodes.UserCodesData.UDCodes[0]["CodeDesc"] = nextPartNumber.ToString();
		adpUserCodes.Update();
		EpiDataView edvDupPart = (EpiDataView)(oTrans.EpiDataViews["NoBoundField"]);
		edvDupPart.dataView[edvDupPart.Row]["DupPart"] = nextPartNumber;
	}
	adpUserCodes.Dispose();
	return nextPartNum;
}

Ross