Click here to Skip to main content
15,897,718 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
If the SelectedValue = 3.5, 4.0 gets inserted?

My SqlDateType is Decimal(18,2)

Here is my DDL code:
XML
<asp:RadioButtonList ID="skillLevelCmbo" runat="server" RepeatLayout="Table" RepeatDirection="Horizontal" CssClass="skillLevel" BackColor="#00f3ff">
     <asp:ListItem Value="2.5">2.5</asp:ListItem>
     <asp:ListItem Value="3.0">3.0</asp:ListItem>
     <asp:ListItem Value="3.5">3.5</asp:ListItem>
     <asp:ListItem Value="4.0">4.0</asp:ListItem>
     <asp:ListItem Value="4.5">4.5</asp:ListItem>
     <asp:ListItem Value="5.0">5.0</asp:ListItem>
     <asp:ListItem Value="5.5">5.5</asp:ListItem>
     <asp:ListItem Value="6.0">6.0</asp:ListItem>
 </asp:RadioButtonList>


Here is my SP insert ADO.NET command:

protected void submitBtn_Click(object sender, EventArgs e)
        {
            //update UserConfirmation Table
            SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["FMLConnection"].ToString());
            SqlCommand cmd = new SqlCommand("dbo.spInsertUserProfileData", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@userName", HttpContext.Current.User.Identity.Name);
            cmd.Parameters.AddWithValue("@firstName", fnameTB.Text);
            cmd.Parameters.AddWithValue("@lastName", lnameTB.Text);
            cmd.Parameters.AddWithValue("@userPhoneNumber", phnTB.Text);
            cmd.Parameters.AddWithValue("@email", emailTB.Text);
            cmd.Parameters.AddWithValue("@userStreetAddress", addressTB.Text);
            cmd.Parameters.AddWithValue("@userCity", cityTB.Text);
            cmd.Parameters.AddWithValue("@userState", Convert.ToString(DropDownListState.SelectedValue));
            cmd.Parameters.AddWithValue("@userZipCode", zipCodeTB.Text);
            cmd.Parameters.AddWithValue("@userBirthDate", DateTime.Parse(birthDate.Text));
            cmd.Parameters.AddWithValue("@userYearsPlayed", Convert.ToInt32(noOfYearsTB.Text));

//This is the Paramater with the issues if the SelectedValue = 3.5, 4.0 gets inserted?
cmd.Parameters.AddWithValue("@userSkillLevel"(Convert.ToDecimal(skillLevelCmbo.SelectedValue)));

            cn.Open();
            IAsyncResult result = cmd.BeginExecuteNonQuery();
            try
            {
                Session.Add("RegistrationComplete", result.IsCompleted);
                cmd.EndExecuteNonQuery(result);
                Response.Redirect("~/MyAccount");
            }
            catch (Exception ex)
            {
                errorsOccured.Text = "An error occurred: " + ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }


Any suggestions would be greatly appreciated.
Posted
Comments
ArunRajendra 18-Oct-13 0:05am    
Might be you need to first track down where the rounding is happening. These are the 3 possible location.

1. DropDownListState.SelectedValue
2. Convert.ToString(DropDownListState.SelectedValue));
3. Stored procedure spInsertUserProfileData.
Harshil_Raval 18-Oct-13 0:34am    
Hi, first debug your code and add watch to this Convert.ToDecimal(skillLevelCmbo.SelectedValue). See it's value is getting roundup or not. If it's value is fine, then check your sp.
Also, you forget to add comma in last parameter,
cmd.Parameters.AddWithValue("@userSkillLevel",(Convert.ToDecimal(skillLevelCmbo.SelectedValue)));

1 solution

Looking at the code it seems rounding off taking place in the Stored Procedure or the data type you defined for skill set is int. Check the data type for Skilllevel column in both the table and the SP
 
Share this answer
 
Comments
JasonMacD 18-Oct-13 8:38am    
You are correct my friend everything was correct in the .aspx/C# and the datetype in the table in my db was also correct. I had the datatype on the parameter set to decimal (18,0) in the sp not allowing for the decimal to the right to be inserted.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900