I am trying to write to a database from my C# Windows Forms app. I am trying to get the text in a comboBox and update that column in the SQL Server Express database, but only based on a condition. I have used an INSERT
statement and that works perfectly, but the UPDATE
does not work.
This is what I've tried:
connectionString.Open();
string serialNumber = "S1478455";
if (cbTransferTo.Text != null && cbTransferTo.Text != "" && cbTransferTo.Text != " ")
{
cmd = new SqlCommand("UPDATE GRV SET [Status] = @status WHERE [Serial Number] = '" + serialNumber + "'", connectionString);
cmd.Parameters.AddWithValue("@status", cbSetStatus.Text);
cmd.ExecuteNonQuery(); //Error occurs here
connectionString.Close();
}
else
{
MessageBox.Show("Please confirm that you have completed the 'Transfer To' text box");
}
Error:
System.Data.SqlClient.SqlException
HResult=0x80131904
Message=Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32).
Source=.Net SqlClient Data ProviderStackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction)
1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource
1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at AMS_Firebase.AssetTransfer.btnTransfer_Click(Object sender, EventArgs e) in C:\Users\Nickitaes\Desktop\AMS_Firebase\AMS_Firebase\AMS_Firebase\AssetTransfer.cs:line 471 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at AMS_Firebase.Program.Main() in C:\Users\Nickitaes\Desktop\AMS_Firebase\AMS_Firebase\AMS_Firebase\Program.cs:line 19
User contributions licensed under CC BY-SA 3.0