Asad khan

Asad khan

  • NA
  • 208
  • 97.6k

Error converting data type varchar to numeric

Oct 29 2018 1:51 AM
My Code is that and How to remove this error?
 
//New Insert / New Entry
if (lblItemcode.Text == "-")
{
string imageName = pid + lblFileExtension.Text;
string sql1 = " insert into purchase (product_id, product_name, product_quantity, cost_price, retail_price, total_cost_price, " +
" total_retail_price, category, supplier , imagename, discount, taxapply, Shopid , status, brand, generic, expiry_date, discount_allowed) " +
" values ('" + pid + "', '" + pname + "', '" + quan + "', '" + cprice + "', '" + sprice + "', '" + ctotalpri + "', " +
" '" + rtotalpri + "', '" + ComboCategory.Text + "', '" + cmbSupplier.Text + "' , '" + imageName + "', " +
" '" + discount + "' , '" + taxapply + "' , '" + cmboShopid.SelectedValue + "' , '"+ kitchenDisplaythisitem + "', '" + comboBrand.Text + "', '" + comboGeneric.Text + "', '" + dateTimePicker1.Text + "', '" + txtdiscountallowed + "')";
DataAccess.ExecuteSQL(sql1);
//Add to purchase history - New item history
insertpurchasehistory("NEW", quan, DateTime.Now.ToString("yyyy-MM-dd"));
//picture upload /////////////////
// if (openFileDialog1.FileName != string.Empty)
// {
string path = Application.StartupPath + @"\ITEMIMAGE\";
System.IO.File.Delete(path + @"\" + imageName);
if (!System.IO.Directory.Exists(path))
System.IO.Directory.CreateDirectory(Application.StartupPath + @"\ITEMIMAGE\");
string filename = path + @"\" + openFileDialog1.SafeFileName;
picItemimage.Image.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
System.IO.File.Move(path + @"\" + openFileDialog1.SafeFileName, path + @"\" + imageName);
// }
MessageBox.Show("Item hase been saved Successfully", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (UserInfo.usertype == "1")
{
Stock_List go = new Stock_List();
go.MdiParent = this.ParentForm;
go.Show();
this.Close();
}
else
{
// btnItemLink.Visible = false;
}
// ClearForm();
}
else //Update
{
string imageName;
if (lblFileExtension.Text == "item.png") //if not select image
{
imageName = lblimagename.Text;
}
else // select image
{
imageName = lblItemcode.Text + lblFileExtension.Text;
}
string sql =" update purchase set product_name = '" + txtProductName.Text + "', product_quantity= '" + txtProductQty.Text + "', " +
" cost_price = '" + txtCostPrice.Text + "', retail_price= '" + txtSalesPrice.Text + "', total_cost_price = '" + ctotalpri + "', " +
" total_retail_price= '" + rtotalpri + "', category = '" + ComboCategory.Text + "', supplier = '" + cmbSupplier.Text + "', " +
" imagename = '" + imageName + "' , discount = '" + discount + "' , taxapply = '" + taxapply + "' , " +
" Shopid = '" + cmboShopid.SelectedValue + "', brand = '" + comboBrand.Text + "', generic = '" + comboGeneric.Text + "', expiry_date = '" + dateTimePicker1.Text + "', discount_allowed = '" + txtdiscountallowed + "' , status = '" + kitchenDisplaythisitem + "' " +
" where product_id = '" + lblItemcode.Text + "'";
DataAccess.ExecuteSQL(sql);
/////////////////////////////////////////////Update image //////////////////////////////////////////////////////
if (lblFileExtension.Text != "item.png") // if select image
{
picItemimage.InitialImage.Dispose();
string path = Application.StartupPath + @"\ITEMIMAGE\";
System.IO.File.Delete(path + @"\" + lblimagename.Text);
if (!System.IO.Directory.Exists(path))
System.IO.Directory.CreateDirectory(Application.StartupPath + @"\ITEMIMAGE\");
string filename = path + @"\" + openFileDialog1.SafeFileName;
picItemimage.Image.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
System.IO.File.Move(path + @"\" + openFileDialog1.SafeFileName, path + @"\" + imageName);
}
MessageBox.Show("Successfully Data Updated!", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
//loadData();
if (UserInfo.usertype == "1")
{
Stock_List go = new Stock_List();
go.MdiParent = this.ParentForm;
go.Show();
this.Close();
}
else
{
// btnItemLink.Visible = false;
}
}
}
catch (Exception exp)
{
MessageBox.Show("Sorry\r\n this id already added \n" + exp.Message);
}
}
//this.Hide();
}
 

Answers (4)