User 6675636b20796f7521 User 6675636b20796f7521 - 1 year ago 62
C# Question

Error Converting data type 'Numeric' to Decimal (help!)

Good Day Everyone,

As of now im stuck with this error

Error Converting data type 'Numeric' to Decimal

this is my code

AddManualItems AddReconItem = new AddManualItems();
UserAccess user = new UserAccess();
AddReconItem.BranchCode = BranchCodeTextBox.Text;
AddReconItem.ForLoanMonth = YearDropDownList.SelectedValue + "/" + MonthDropDownList.SelectedValue;
AddReconItem.ItemWeight = Convert.ToDecimal(WeightTextBox.Text);
AddReconItem.PrincipalAmount = Convert.ToDecimal(PrincipalTexAmTextBox.Text);
AddReconItem.PawnTicket = PwnTicketTextBox.Text;
AddReconItem.ItemStorageGroup = Convert.ToInt16(StorageNameDropDownList.SelectedValue);
AddReconItem.ReconID = Convert.ToInt16(ReconTypeDropDownList.SelectedValue);
user.UserID = Session["UserID"].ToString();

string a = servs.AddItemRecon(user, AddReconItem); // this is where the error appears in debug mode

the code inside of the ADDitemRecon(User,AddReconItem) is this

using (SqlConnection reportsConn = new SqlConnection(sqlConnWriter))
SqlCommand AddReconItem = new SqlCommand();
AddReconItem.Connection = reportsConn;
AddReconItem.CommandType = CommandType.StoredProcedure;
AddReconItem.CommandText = "Updater.usp_AddReconcileItems";
AddReconItem.Parameters.AddWithValue("@ITEMWEIGHT", Convert.ToDecimal( items.ItemWeight));
AddReconItem.Parameters.AddWithValue("@ITEMPRINCIPALAMT", Convert.ToDecimal(items.PrincipalAmount));
AddReconItem.Parameters.AddWithValue("@FORLOANMONTH", Convert.ToDateTime(items.ForLoanMonth));
AddReconItem.Parameters.AddWithValue("@STORAGEGROUPID", items.ItemStorageGroup);
AddReconItem.Parameters.AddWithValue("@BRANCHCODE", items.BranchCode);
AddReconItem.Parameters.AddWithValue("RECONID", items.ReconID);
AddReconItem.Parameters.AddWithValue("@CREATEDBY", user.UserID.ToString());

my property for ItemWeight is

private decimal itemWeight;

public decimal ItemWeight
get { return itemWeight; }
set { itemWeight = value; }

i bet the error is in the item weight because when i input in the item weight
12345.12 it works fine, but when i input 1234 instead of treating it as 1234.00 it treats it as 1234 only making it numeric..

any help? i do not know if my conversions are wrong

By the way my field in database is

fld_ItemWeight (decimal (38,6), not null

Is there any bugs known in Decimal?? im using VS 2005 as of now.

Answer Source

Found The answer! my stored Procedure is wrong i have decimal(9,6) in my stored procedured making it accept 3 digits or less !changed it to (18,2)\

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download