sathish kumar

sathish kumar

  • NA
  • 117
  • 165.2k

Sql Upation error: in sql2008: Error converting data type varchar to numeric

Jul 16 2012 1:21 AM

Hi friends i m geeting  Error (converting data type varchar to numeric) while updating the table.I have to update the below table based on the condintion

CREATE TABLE [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("<script language='javascript'>alert('Entry Not Selected for Modification!!!');</script>");
  }
  else
  {
  Update_Record();
  }




protected void Update_Record()
  {
  try
  { 
  string strSQL; 
  string dbConn = ConfigurationManager.ConnectionStrings["CMC"].ConnectionString;
  SqlConnection sqlConn = new SqlConnection(dbConn);
  sqlConn.Open();
  string PRate = Convert.ToInt32(txtPurchaseRate.Text).ToString();
  string MRP = Convert.ToInt32(txtPurchaseMRP.Text).ToString();
  string Oqty = Convert.ToInt32(txtOpeningQuantity.Text).ToString();
  string Ovalue = Convert.ToInt32(txtOpeningValue.Text).ToString();
  string Rlevel = Convert.ToInt32(txtReorderLevel.Text).ToString();
  string MinValue = Convert.ToInt32(txtMinStockQty.Text).ToString();
  string MaxValue = Convert.ToInt32(txtMaxStockQty.Text).ToString();
  string Vat = Convert.ToInt32(txtVAT.Text).ToString();

  strSQL = "Update [ITEMMASTER] Set ITEMDESCRIPTION='" + txtItemDescription.Text + "',BRAND='" + DDLBrand.SelectedItem.ToString() + "',ITEMGROUP='" + DDLItemGroup.SelectedItem.ToString() + "',ITEMUNIT='" + DDLItemUnit.SelectedItem.ToString() + "',MANUFACTURER='" + DDLMfr.SelectedItem.ToString() + "',PURCHASERATE='" + PRate + "',PURCHASEMRP='" + MRP + "',OPENINGQTY='" + Oqty + "',OPENINGVALUE='" + Ovalue + "', REORDERLEVEL='" + Rlevel + "',MINSTOCKQTY='" + MinValue + "',MAXSTOCKQTY='" + MaxValue + "',VATPERCENT='" + Vat + "' Where ITEMCODE ='" + txtItemCode.Text + "'";
  SqlCommand cmdItemMaster = new SqlCommand(strSQL, sqlConn);
  cmdItemMaster.ExecuteNonQuery();
  sqlConn.Close();
  Response.Write("<script language='javascript'>alert('Data Updated Successfully...');</script>");
  Load_Record();
 
  }
  catch (Exception)
  {
  Response.Write("<script language='javascript'>alert(' Entry Not selected for Updation...');</script>");
  }
  }


But it shows error....if  PURCHASERATE, PURCHASEMRP, OPENINGQTY,OPENINGVALUE,REORDERLEVEL,MINSTOCKQTY,MAXSTOCKQTY,VATPERCENT fields are not entered. But i want to update it even the values are not entered. 

The Error is :   Error converting data type varchar to numeric
Help me please...Its urgent

Answers (16)