This error come up "Error converting data type nvarchar to bigint." when the user clicks the Submit button. I have two other web forms that connect to the same database and didn't get this error. Here is the error code:
Error converting data type nvarchar to bigint.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Error converting data type nvarchar to bigint.
Source Error:
Line 275: cmd.Parameters.AddWithValue("@LongName", lblSchool.Text);
Line 276:
Line 277: cmd.ExecuteNonQuery();
Line 278: }
Line 279: else if (temp == 1)
Stack Trace:
[SqlException (0x80131904): Error converting data type nvarchar to bigint.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +1787814
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5341674
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +546
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1693
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +275
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) +1421
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +177
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) +208
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +163
FINAPP.FINProFormD.ButtonSubmit_Click(Object sender, EventArgs e) in C:\Users\khopkins\Documents\visual studio 2010\Projects\FINAPP\FINAPP\FINProFormD.aspx.cs:277
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9627994
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
Here is the C# code:
protected void ButtonSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con.Open();
const string cmdStr = "Select count(*) from Table99 where User_ID= @User_ID AND FINYEAR = 2015";
SqlCommand userExist = new SqlCommand(cmdStr, con);
userExist.Parameters.AddWithValue("@User_ID", TextBoxUser_ID.Text);
userExist.Parameters.AddWithValue("@FINYEAR", TextBoxDATE2.Text);
int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
if (temp == 0)
{
SqlCommand cmd = new SqlCommand("Insert into Table99 (User_ID, TOTAL_REVE, DATE, FINYEAR, INSTRUCTIO, RESEARCH, ACADEMIC_S, NET_AID, AUXILIARY_, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT, EXPENDABLE, TOTALNETASSETS, LongName, SUBMITTED) values (@USer_ID, @TOTAL_REVE, @DATE, @FINYEAR, @INSTRUCTIO, @RESEARCH, @ACADEMIC_S, @NET_AID, @AUXILIARY_, @OTHEREXP, @TOTASSETS, @TOTLIABILITY, @NoNEXPPERMRESASSETS, @UNRNETASSETS, @TOTALREV, @TUITFEES, @CURRDEBT, @LONGTERMDEBT, @EXPENDABLE, @TOTALNETASSETS, @LongName, @SUBMITTED);", con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@User_ID", TextBoxUser_ID.Text);
cmd.Parameters.AddWithValue("@TOTAL_REVE", TextBoxTRR.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@INSTRUCTIO", TextBoxInstr.Text);
cmd.Parameters.AddWithValue("@RESEARCH", TextBoxResPs.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@ACADEMIC_S", TextBoxAcadSSSIS.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@NET_AID", TextBoxNGAS.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@AUXILIARY_", TextBoxAuxE.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@OTHEREXP", TextBoxAOE.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@TOTASSETS", TextBoxTA.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@TOTLIABILITY", TextBoxTL.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@NoNEXPPERMRESASSETS", TextBoxNPRNA.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@EXPENDABLE", TextBoxETRNA.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@UNRNETASSETS", TextBoxTUNA.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@TOTALREV", TextBoxTR.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@TUITFEES", TextBoxTFN.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@CURRDEBT", TextBoxCD.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@LONGTERMDEBT", TextBoxLTD.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@FINYEAR", TextBoxDATE2.Text);
cmd.Parameters.AddWithValue("@SUBMITTED", lblFalse.Text);
cmd.Parameters.AddWithValue("@DATE", TextBoxDATE.Text);
cmd.Parameters.AddWithValue("@TOTALNETASSETS", TextBoxTNA.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@LongName", lblSchool.Text);
cmd.ExecuteNonQuery();
Did I forget something in my code or did something wrong?