Cannot implicity convert string type to decimal

I am trying to save a field to a table but get the following error message

Cannot implicity convert string type to decimal

I know it is because I am mishandling a variable before I write it to the database, but I am not sure how to tell it what I want to do.

All I want to do is read a field call documentid which is a decimal (9,4) from a table.  Then add .001 to the value and then save it back to the table.  I know it is because I am using the Tostring() command but I am not sure of the syntax to correctly conver the value.  Can someone point me in the right direction.

Here is my code:

decimal id;------------------------------------------------------------------------Variable is defined here
            string taxid;
            string userid;
            string username;

            SqlCommand oCmd;
            SqlConnection oConn;
            SqlDataReader reader = null;

            oConn = new SqlConnection();
            oConn.ConnectionString = ConfigurationManager.ConnectionStrings["12331ConnectionString"].ConnectionString;
       
            oConn.Open();
            //use stored proc name here
            oCmd = new SqlCommand("ReadDRRIdCntr", oConn);
            oCmd.CommandType = CommandType.StoredProcedure;


            // Get the data
            reader = oCmd.ExecuteReader();
           
       
            reader.Read();
   



            if (reader.HasRows)
            {
                id = reader["id"].ToString();-----------------------------------------Here is where I get the error when I attempt to add
                id = id + .0001;
                Session.Add("id", id);
            }
kwh3856OwnerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Arthur_WoodCommented:
change this line:
id = reader["id"].ToString();
to:

id = reader["id"].GetDecimal()
 
you are trying to assign a String value (reader["id"].ToString()) to a variable declared as decimal.
 
AW
0
Dirk HaestProject managerCommented:
Try this:
id = (decimal)reader["id"].ToString();
0
Dirk HaestProject managerCommented:
Also possible:

id = Convert.ToDecimal(reader["id"].ToString())
or
id = Decimal.Parse(reader["id"].ToString())

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kwh3856OwnerAuthor Commented:
id = Convert.ToDecimal(reader["id"].ToString())

awesome!!!! that did it.

Thanks
Kenny
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.