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;
            //use stored proc name here
            oCmd = new SqlCommand("ReadDRRIdCntr", oConn);
            oCmd.CommandType = CommandType.StoredProcedure;

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

            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);
Who is Participating?
DhaestConnect With a Mentor Commented:
Also possible:

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

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

id = reader["id"].GetDecimal()
you are trying to assign a String value (reader["id"].ToString()) to a variable declared as decimal.
Try this:
id = (decimal)reader["id"].ToString();
kwh3856Author Commented:
id = Convert.ToDecimal(reader["id"].ToString())

awesome!!!! that did it.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.