2 Replies - 1222 Views - Last Post: 03 April 2012 - 10:49 AM Rate Topic: -----

#1 insen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-April 12

Error: Input string was not in a correct format

Posted 03 April 2012 - 10:36 AM

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication1
{
    public partial class frmAddProduct : Form
    {

        private CoffeeShopDatabaseEntities cse = new CoffeeShopDatabaseEntities();

        private Byte[] byteBLOBData;



        public frmAddProduct()
        {
            InitializeComponent();

            cboCategory.DataSource = cse.TblProductTypes;
            cboCategory.DisplayMember = "Description";
            cboCategory.ValueMember = "ProductType";
        }

        private void btnUpload_Click(object sender, EventArgs e)
        {
            DialogResult result = openFileDialog1.ShowDialog();

            if (result == DialogResult.OK)
            {
                FileStream fsBLOBFile = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);

                byteBLOBData = new Byte[fsBLOBFile.Length];

                fsBLOBFile.Read(byteBLOBData, 0, byteBLOBData.Length);

                fsBLOBFile.Close();

                MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);

                pbImage.Image = Image.FromStream(stmBLOBData);

            }

        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            {
                TblProduct product = new TblProduct();

                product.Description = txtDescription.Text;

                product.Price = decimal.Parse(txtPrice.Text);

                product.Image = byteBLOBData;

                product.ProductType = (int)cboCategory.SelectedValue;

                cse.AddToTblProducts(product);

                cse.SaveChanges();

                MessageBox.Show("Record Saved");
          }
       }

    }
}

Problem: "product.Price = decimal.Parse(txtPrice.Text);"
Input string was not in a correct format.

This post has been edited by tlhIn`toq: 03 April 2012 - 10:43 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Error: Input string was not in a correct format

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5498
  • View blog
  • Posts: 11,804
  • Joined: 02-June 10

Re: Error: Input string was not in a correct format

Posted 03 April 2012 - 10:45 AM

First: Use code tags like it says right there in the box you typed your message in.
:code:

Second: There are more than 500,000 users on the DIC. Can you imagine if they all started threads as "Problem" ? Please use meaningful titles so the people with the most knowledge in your area are drawn to your question. This also helps people later using search engines to find they help they need.

Third: You can't convert a string like "YogiBear" to the number 5 and that what it is telling you.
You problem is covered in this article:
What does this error mean?
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6062
  • View blog
  • Posts: 23,513
  • Joined: 23-August 08

Re: Error: Input string was not in a correct format

Posted 03 April 2012 - 10:49 AM

Changed title. Please do NOT use topic titles like "Error" or "Problem". Give a very brief idea of the problem you're having.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1