skearney
(Shannon Kearney)
June 26, 2019, 2:18pm
1
I have some kind of issue in my conversion I’m assuming. Anyone have any ideas? Here is the error:
My BAQ column I am trying to return is formatted as “Decimal”
I am trying to insert that value into a number editor box.
My code is:
//Remake Calculation Dynamic Query
public void SaveandCalculateRemake()
{
DynamicQueryAdapter dqaIPR = new DynamicQueryAdapter(oTrans);
dqaIPR.BOConnect();
QueryExecutionDataSet qedsIPR = dqaIPR.GetQueryExecutionParametersByID("GS_InPlantRemakeCalculation");
qedsIPR.ExecutionParameter.Clear();
qedsIPR.ExecutionParameter.AddExecutionParameterRow("OrderNum", "100753" , "nvarchar", false, Guid.NewGuid(), "IPR");
qedsIPR.ExecutionParameter.AddExecutionParameterRow("OrderLine", "1" , "nvarchar", false, Guid.NewGuid(), "IPR");
dqaIPR.ExecuteByID("GS_InPlantRemakeCalculation", qedsIPR);
gridRemakeData.DataSource = dqaIPR.QueryResults.Tables["Results"];
//ERROR HAPPENING HERE:
neTotalRemakeAmount.Value = gridRemakeData.ActiveRow.Cells["Calculated_TotalRemakeCost"].Value;
}
Is there an ActiveRow at this point?
Maybe try getting the first SelectedRow? Also, is that column name correct?
skearney
(Shannon Kearney)
June 26, 2019, 2:30pm
3
How do I get the first selected row? and yest the column name is correct - It is a calculated field in the BAQ.
jkane
(John Kane)
June 26, 2019, 2:33pm
4
Why not convert the field to Int in the BAQ?
1 Like
skearney
(Shannon Kearney)
June 26, 2019, 2:33pm
5
I tried that too and I couldn’t get it to work.
Here is some basics:
.net, ultrawingrid
Your error does not appear to be an integer conversion issue… yet.
Hogardy
(Pierre Hogue)
June 26, 2019, 2:42pm
7
neTotalRemakeAmount.Value = gridRemakeData.ActiveRow.Cells["Calculated_TotalRemakeCost"].Value;
How about casting the value when reading it? if neTotalRemakeAmount is int…
neTotalRemakeAmount.Value = (int)(decimal) gridRemakeData.ActiveRow.Cells["Calculated_TotalRemakeCost"].Value;
skearney
(Shannon Kearney)
June 26, 2019, 3:04pm
8
Okay, I got this to work. It wasn’t finding a value in the grid was the problem. Here is the code that is working:
//Remake Calculation Dynamic Query
public void SaveandCalculateRemake()
{
DynamicQueryAdapter dqaIPR = new DynamicQueryAdapter(oTrans);
dqaIPR.BOConnect();
QueryExecutionDataSet qedsIPR = dqaIPR.GetQueryExecutionParametersByID("GS_InPlantRemakeCalculation");
qedsIPR.ExecutionParameter.Clear();
qedsIPR.ExecutionParameter.AddExecutionParameterRow("OrderNum", "100753" , "nvarchar", false, Guid.NewGuid(), "IPR");
qedsIPR.ExecutionParameter.AddExecutionParameterRow("OrderLine", "1" , "nvarchar", false, Guid.NewGuid(), "IPR");
dqaIPR.ExecuteByID("GS_InPlantRemakeCalculation", qedsIPR);
gridRemakeData.DataSource = dqaIPR.QueryResults.Tables["Results"];
{
if (dqaIPR.QueryResults.Tables["Results"].Rows.Count >= 1)
{
foreach (System.Data.DataRow IPR in dqaIPR.QueryResults.Tables["Results"].Rows)
{
neTotalRemakeAmount.Value = Convert.ToDecimal(IPR["Calculated_TotalRemakeCost"].ToString());
}
}
}
}
I have found that I have stopped using Convert.To function and used the Parse versions. I just put it in a try block and gracefully handle the exceptions instead of throwing an exception to the user.
More info on ParseDecimal…
2 Likes
I prefer
Decimal.TryParse(myString, out myDecimal);
I can use it like:
string myString = "0.1";
decimal myDecimal;
if (Decimal.TryParse(myString, out myDecimal))
return myDecimal * 100;
else
{
MessageBox.Show("Couldn't make that value a decimal!");
return -1;
}
3 Likes