While inserting it shows ERROR: converting varchar to numeric ..using c#.net
CREATE TABLE [dbo].[ITEMMASTER](
[ID] [int] NULL,
[ITEMCODE] [varchar](10) NULL,
[ITEMDESCRIPTION] [varchar](50) NULL,
[BRAND] [varchar](50) NULL,
[ITEMGROUP] [varchar](50) NULL,
[ITEMUNIT] [varchar](50) NULL,
[PURCHASERATE] [numeric](12, 2) NULL,
[MANUFACTURER] [varchar](50) NULL,
[PURCHASEMRP] [numeric](12, 2) NULL,
[OPENINGQTY] [numeric](12, 2) NULL,
[OPENINGVALUE] [numeric](12, 2) NULL,
[ISACTIVE] [bit] NULL,
[REORDERLEVEL] [numeric](12, 2) NULL,
[MINSTOCKQTY] [numeric](12, 2) NULL,
[MAXSTOCKQTY] [numeric](12, 2) NULL,
[VATPERCENT] [varchar](50) NULL
) ON [PRIMARY]
if (txtItemCode.Text == "")
{
Response.Write("");
}
else
{
Save_Record();
}
protected void Save_Record()
{
try
{
if (validate_data())
{
string strSQL;
string dbConn = ConfigurationManager.ConnectionStrings["CMC"].ConnectionString;
SqlConnection sqlConn = new SqlConnection(dbConn);
sqlConn.Open();
strSQL = "INSERT INTO [ITEMMASTER](ITEMCODE,ITEMDESCRIPTION,BRAND,ITEMGROUP,ITEMUNIT,PURCHASERATE,MANUFACTURER,PURCHASEMRP,OPENINGQTY,OPENINGVALUE,REORDERLEVEL,MINSTOCKQTY,MAXSTOCKQTY,VATPERCENT)VALUES ('" + txtItemCode.Text + "','" + txtItemDescription.Text + "','" +DDLBrand.SelectedItem.ToString() + "','" +DDLItemGroup.SelectedItem.ToString() + "','" +DDLItemUnit.SelectedItem.ToString() + "','" +txtPurchaseRate.Text + "','" +DDLMfr.SelectedItem.ToString() + "','" +txtPurchaseMRP.Text + "','" +txtOpeningQuantity.Text + "', '" +txtOpeningValue.Text + "','" +txtReorderLevel.Text + "','" +txtMinStockQty.Text + "','" +txtMaxStockQty.Text + "','" +txtVAT.Text + "' )";
//strSQL = "INSERT INTO [ITEMMASTER](ITEMCODE,ITEMDESCRIPTION,BRAND,ITEMGROUP,ITEMUNIT,PURCHASERATE,MANUFACTURER,PURCHASEMRP,OPENINGQTY,OPENINGVALUE,REORDERLEVEL,MINSTOCKQTY,MAXSTOCKQTY,VATPERCENT)VALUES ('" + txtItemCode.Text + "','" + txtItemDescription.Text + "','" +
// DDLBrand.SelectedItem.ToString() + "','" +
// DDLItemGroup.SelectedItem.ToString() + "','" +
// DDLItemUnit.SelectedItem.ToString() + "','" +
// (string.IsNullOrEmpty(txtPurchaseRate.Text) ? "0.0" : txtPurchaseRate.Text) + "','" +
// DDLMfr.SelectedItem.ToString() + "','" +
// (string.IsNullOrEmpty(txtPurchaseMRP.Text) ? "0.0" : txtPurchaseMRP.Text) + "','" +
// (string.IsNullOrEmpty(txtOpeningQuantity.Text) ? "0.0" : txtOpeningQuantity.Text) + "', '" +
// (string.IsNullOrEmpty(txtOpeningValue.Text) ? "0.0" : txtOpeningValue.Text) + "','" +
// (string.IsNullOrEmpty(txtReorderLevel.Text) ? "0.0" : txtReorderLevel.Text) + "','" +
//(string.IsNullOrEmpty(txtMinStockQty.Text) ? "0.0" : txtMinStockQty.Text) + "','" +
// (string.IsNullOrEmpty(txtMaxStockQty.Text) ? "0.0" : txtMaxStockQty.Text) + "','" +
// txtVAT.Text + "' )";
SqlCommand cmdItemMaster = new SqlCommand(strSQL, sqlConn);
cmdItemMaster.ExecuteNonQuery();
sqlConn.Close();
Response.Write("");
Load_Record();
Record_Count();
}
}
catch (Exception)
{
Response.Write("");
}
}
ABOVE IS MY TABLE AND QUERY... While inserting it shows ERROR: converting varchar to numeric .. Anyone pls help me......
Loading
Jignesh TrivediPosted Jul 25, 2012, 3:40 AM
I think error is same as below thread.
http://www.c-sharpcorner.com/Forums/Thread/179448/sql-upation-error-in-sql2008-error-converting-data-typ.aspx
try....
strSQL = "INSERT INTO [ITEMMASTER](ITEMCODE,ITEMDESCRIPTION,BRAND,ITEMGROUP,ITEMUNIT,PURCHASERATE,MANUFACTURER,PURCHASEMRP,OPENINGQTY,OPENINGVALUE,REORDERLEVEL,MINSTOCKQTY,MAXSTOCKQTY,VATPERCENT)VALUES ('"
+ txtItemCode.Text + "','"
+ txtItemDescription.Text + "','"
+ DDLBrand.SelectedItem.ToString() + "','"
+ DDLItemGroup.SelectedItem.ToString() + "','"
+ DDLItemUnit.SelectedItem.ToString() + "','"
+ txtPurchaseRate.Text + "','"
+ DDLMfr.SelectedItem.ToString() + "','"
+ (string.IsNullOrEmpty(txtPurchaseMRP.Text) ? "0.0" : txtPurchaseMRP.Text) + "','"
+ (string.IsNullOrEmpty(txtOpeningQuantity.Text) ? "0.0" : txtOpeningQuantity.Text) + "', '"
+ (string.IsNullOrEmpty(txtOpeningValue.Text) ? "0.0" : txtOpeningValue.Text) + "','"
+ (string.IsNullOrEmpty(txtReorderLevel.Text) ? "0.0" : txtReorderLevel.Text) + "','"
+ (string.IsNullOrEmpty(txtMinStockQty.Text) ? "0.0" : txtMinStockQty.Text) + "','"
+ (string.IsNullOrEmpty(txtMaxStockQty.Text) ? "0.0" : txtMaxStockQty.Text) + "','"
+ (string.IsNullOrEmpty(txtVAT.Text) ? "0.0" : txtVAT.Text) + "' )";
hope this will help you.
Santhosh Kumar JayaramanPosted Jul 25, 2012, 1:27 AM