Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to save my data from a form that I developed. On one record I get this error:

C#
Conversion failed when converting the nvarchar value 'Infinity' to data type int.

The error is coming from this line:
C#
cmd2.ExecuteNonQuery();

Here is my codebehind:
C#
SqlCommand cmd2 = new SqlCommand("Insert into TableFA (User_ID, FT_UNDERGR, DATE, FT_GRAD, FTE_UNDERG, FTE_GRAD, NON_CREDIT, TOTAL_FTE, FCFTUHC, FCFTPBHC, FCPTUHC, FCPTPBHC, NCHC, UnderG12, Postb9, Total123b4b, FTEYR, THCAS, FTE40, HC50, NCA, SUBMITTED, Calendar, LongName) values (@User_ID, @FT_UNDERGR, @DATE, @FT_GRAD, @FTE_UNDERG, @FTE_GRAD, @NON_CREDIT, @TOTAL_FTE, @FCFTUHC, @FCFTPBHC, @FCPTUHC, @FCPTPBHC, @NCHC, @UnderG12, @Postb9, @Total123b4b, @FTEYR, @THCAS, @FTE40, @HC50, @NCA, @SUBMITTED, @Calendar, @LongName);", con);
                cmd2.CommandType = CommandType.Text;
                cmd2.Parameters.AddWithValue("@INST_ID", TextBoxUser_ID.Text);
                cmd2.Parameters.AddWithValue("@FT_UNDERGR", TextBoxFTUG.Text.Replace(",", ""));
                cmd2.Parameters.AddWithValue("@FT_GRAD", TextBoxFTG.Text.Replace(",", ""));
                cmd2.Parameters.AddWithValue("@FTE_UNDERG", TextBoxTHUGDR.Text.Replace(",", ""));
                cmd2.Parameters.AddWithValue("@FTE_GRAD", TextBoxTHGDR.Text.Replace(",", ""));
                cmd2.Parameters.AddWithValue("@NON_CREDIT", TextBoxNCCDR.Text.Replace(",", ""));
                cmd2.Parameters.AddWithValue("@TOTAL_FTE", TextBoxTCNC.Text.Replace(",", ""));
                cmd2.Parameters.AddWithValue("@FCFTUHC", TextBoxTNFUG.Text.Replace(",", ""));
                cmd2.Parameters.AddWithValue("@FCFTPBHC", TextBoxTNFG.Text.Replace(",", ""));
                cmd2.Parameters.AddWithValue("@FCPTUHC", TextBoxTNCPUG.Text.Replace(",", ""));
                cmd2.Parameters.AddWithValue("@FCPTPBHC", TextBoxTNCPG.Text.Replace(",", ""));
                cmd2.Parameters.AddWithValue("@NCHC", TextBoxTNNCC.Text.Replace(",", ""));
                cmd2.Parameters.AddWithValue("@FTEYR", lblYEAR1.Text);
                cmd2.Parameters.AddWithValue("@DATE", TextBoxDATE.Text);
                cmd2.Parameters.AddWithValue("@UnderG12", TextBoxTHUG.Text.Replace(",", ""));
                cmd2.Parameters.AddWithValue("@Postb9", TextBoxTHG.Text.Replace(",", ""));
                cmd2.Parameters.AddWithValue("@Total123b4b", TextBoxT1234.Text.Replace(",", ""));
                cmd2.Parameters.AddWithValue("@THCAS", TextBoxTHCAS.Text.Replace(",", ""));
                cmd2.Parameters.AddWithValue("@FTE40", TextBoxFTE40.Text.Replace(",", ""));
                cmd2.Parameters.AddWithValue("@HC50", TextBoxHC50.Text.Replace(",", ""));
                cmd2.Parameters.AddWithValue("@NCA", TextBoxNCC.Text.Replace(",", ""));
                cmd2.Parameters.AddWithValue("@SUBMITTED", lblSub.Text);
                cmd2.Parameters.AddWithValue("@Calendar", TextBoxCal.Text);
                cmd2.Parameters.AddWithValue("@LongName", lblSchool.Text);

                cmd2.ExecuteNonQuery();

Why am I getting this error just on this record and not the others? What did I do wrong?
Posted

The error should be very clear, isn't it? It says you are trying to store the string value "Infinity" into a field that can only store integers. The word "infinity" clearly is not an integer, neither is the actual value of infinity, but I digress.
 
Share this answer
 
Comments
Computer Wiz99 8-Dec-15 15:47pm    
Where is this value? I am typing in numbers. And why is this just the only record?
ZurdoDev 8-Dec-15 15:58pm    
How can we tell where the value is? We can't access your system or run your code. You'll have to find it. If indeed the above code is causing it then it is in one of your controls.

You could always run Sql Server Profiler as well to see the exact sql getting sent to the server.
Computer Wiz99 8-Dec-15 16:06pm    
Okay, thanks. I will look again.
ZurdoDev 8-Dec-15 16:08pm    
It's there or in a trigger or somewhere. Should be pretty easy to find using profiler.
I found out what is was!! Had to change the database numbers it was populating from zeros to a real whole number.
 
Share this answer
 

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