didonato
8 years agoCreator II
Not a single item
I’m trying to retrieve a value from a legacy database using federation. Here is what I’ve done:
1. Added a new field in “Part” ItemType “and named it “min_total_stock” with type “Federation”
2. Added field “min_total_stock” to Part FORM
3. Created a new method “MIN_Calculate_Total_Stock1” – see below
4. Added METHOD “MIN_Calculate_Total_Stock1” to “Part” ItemType within “Server Events” tab with event “onAfterGet”
When filtering Parts for a single record, it works fine (a value for “min_total_stock” shows in form, but if many records are return in the grid I get an error message “Not a single item”
Any help would be appreciated
Thanks
//==MIN_Calculate_Total_Stock1===//
string masterpart = this.getProperty("item_number");
System.Data.OleDb.OleDbConnection myConnection = new System.Data.OleDb.OleDbConnection(@"Provider=SQLOLEDB;Data Source=000.00.000.0; Initial Catalog=WaspTrackInventory; User ID=admin;Password=Pass;");
string SQL = "select item_number,xqty from WaspTrackInventory.dbo.xArasPartQtySum where item_number = '" + masterpart + "';";
System.Data.OleDb.OleDbCommand com = new System.Data.OleDb.OleDbCommand(SQL);
com.Connection = myConnection;
myConnection.Open();
System.Data.OleDb.OleDbDataReader myDataReader = com.ExecuteReader();
if (myDataReader.HasRows != true)
{
this.setProperty("min_total_stock","None");
}
else
while (myDataReader.Read()) {
this.setProperty("min_total_stock",myDataReader.GetString(1));
}
myConnection.Close();
return this;