Sto tentando di aggiornare un DataTable che viene recuperato da un DB prima di collegarlo a Gridview.DataRow sta azzerando la parte decimale di un decimale quando si aggiorna Datatable
Tuttavia, quando aggiorno i campi decimali, la parte dopo il punto decimale viene azzerata. Cosa mi manca?
if (HttpContext.Current.Request.IsAuthenticated)
{
// Get additional price matches
using (SqlConnection stockConn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString))
{
// Check for trade match offer
SqlCommand tradePCCheck = new SqlCommand("getAllMyPriceMatches", stockConn);
tradePCCheck.CommandType = CommandType.StoredProcedure;
SqlParameter email = tradePCCheck.Parameters.Add("@email", SqlDbType.NVarChar);
try
{
email.Value = this.Context.User.Identity.Name;
}
catch
{
email.Value = " ";
}
SqlParameter thedate = tradePCCheck.Parameters.Add("@theDate", SqlDbType.DateTime);
thedate.Value = DateTime.Now.AddHours(-50);
stockConn.Open();
SqlDataReader pcReader = tradePCCheck.ExecuteReader();
pms.Load(pcReader);
pcReader.Close();
stockConn.Close();
}
}
//Set Connection, Open the DB & Fill Data Set
using (SqlConnection stockConn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString))
{
SqlCommand stockCommand = new SqlCommand("getTISearchResults", stockConn);
stockCommand.CommandType = CommandType.StoredProcedure;
SqlParameter keyword = stockCommand.Parameters.Add("@keyword", SqlDbType.NVarChar);
keyword.Value = prefixText;
stockConn.Open();
SqlDataReader rd = stockCommand.ExecuteReader();
searchResults.Load(rd);
stockCommand.Dispose();
rd.Dispose();
}
// Update Results with elevated prices...
foreach (DataRow dr in searchResults.Rows)
{
// Check for PMS
DataRow[] thePMS = pms.Select("tpc_stockid = '" + dr["stockitem_number"].ToString() + "'");
if (thePMS.Length > 0)
{
decimal px = 0;
decimal cash = 0;
if (thePMS[0]["tpc_pricepx"] != null && !thePMS[0]["tpc_pricepx"].ToString().Equals(""))
{
px = Convert.ToDecimal(thePMS[0]["tpc_pricepx"]);
}
if (thePMS[0]["tpc_price"] != null && !thePMS[0]["tpc_price"].ToString().Equals(""))
{
cash = Convert.ToDecimal(thePMS[0]["tpc_price"]);
}
// update table and accept changes
DataRow[] theRows = searchResults.Select("stockitem_number = '" + dr["stockitem_number"].ToString() + "' ");
if (theRows.Length > 0)
{
theRows[0]["stockitem_pxprice"] = px;
theRows[0]["stockitem_cashprice"] = cash;
searchResults.AcceptChanges();
}
}
}
gvSearchResults.DataSource = searchResults;
gvSearchResults.DataBind();
devo PX uscita e Cash prima della cessione e tengono i valori corretti di 800,19 e 500,12, ma dopo i AcceptChanges e una volta che sono legati, l'uscita è 800,00 e 500,12.
theRows[0]["stockitem_pxprice"]
& theRows[0]["stockitem_cashprice"]
sono entrambi decimal(5,2)
sul DB dove il searchResultsDT è popolato da.
Qualsiasi aiuto molto apprezzato.
Grazie.
Quali sono i valori intermedi di 'px' e' cash' dopo la chiamata 'Convert.ToDecimal()'? Guarderei alla possibilità di un problema culturale, qui, ma il fatto che uno funzioni correttamente e l'altro non sembra davvero strano. –
Dichiarate la struttura (schema) di 'searchResults' prima di caricarla da' SqlReader'? Forse il tuo 'stockitem_pxprice' è dichiarato come' typeof (int) '? –
Verificare la dichiarazione/definizione dei risultati ricerca dati. Potrebbe esserci un qualche tipo di disallineamento –