无法使用SQL Update语句从C#应用程序写入数据库

时间:2019-05-31 14:03:30

标签: c# sql

我正在尝试从C#Windows Forms应用程序写入数据库。我正在尝试在comboBox中获取文本并更新SQL Server Express数据库中的该列,但仅基于条件。我已经使用了INSERT语句,并且效果很好,但是UPDATE无效。

这是我尝试过的:

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");
}

错误:

  

System.Data.SqlClient.SqlException
  HResult = 0x80131904
  Message =已超过最大存储过程,函数,触发器或视图嵌套级别(限制32)。
  Source = .Net SqlClient数据提供程序

     

StackTrace:

     

在System.Data.SqlClient.SqlConnection.OnError(SqlException异常,布尔值breakConnection,操作1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction)
  在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj,布尔调用方HasConnectionLock,布尔asyncClose)
  在System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj,Boolean和dataReady)          在System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior runBehavior,字符串resetOptionsString,布尔值isInternal,布尔值forDescribeParameterEncryption,布尔值shouldCacheForAlwaysEncrypted)          在System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,Boolean异步,Int32超时,Task&task,Boolean asyncWrite,Boolean inRetry,SqlDataReader ds,Boolean describeParameterEncryptionRequest)          在System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,布尔返回流,字符串方法,TaskCompletionSource 1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource 1完成,字符串methodName,布尔sendToPipe,Int32超时,布尔与usedCache,布尔asyncWrite,布尔inRetry)处          在System.Data.SqlClient.SqlCommand.ExecuteNonQuery()          在AMS_Firebase.AssetTransfer.btnTransfer_Click(Object sender,EventArgs e)中的C:\ Users \ Nickitaes \ Desktop \ AMS_Firebase \ AMS_Firebase \ AMS_Firebase \ AssetTransfer.cs:line 471          在System.Windows.Forms.Control.OnClick(EventArgs e)          在System.Windows.Forms.Button.OnClick(EventArgs e)          在System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)          在System.Windows.Forms.Control.WmMouseUp上(消息和m,MouseButtons按钮,Int32单击)          在System.Windows.Forms.Control.WndProc(Message&m)          在System.Windows.Forms.ButtonBase.WndProc(Message&m)          在System.Windows.Forms.Button.WndProc(Message&m)          在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m)          在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)          在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)          在System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&msg)          在System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID,Int32原因,Int32 pvLoopData)          在System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32原因,ApplicationContext上下文)          在System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32原因,ApplicationContext上下文)          在System.Windows.Forms.Application.Run(Form mainForm)          在AMS_Firebase.Program.Main()中的C:\ Users \ Nickitaes \ Desktop \ AMS_Firebase \ AMS_Firebase \ AMS_Firebase \ Program.cs:line 19

0 个答案:

没有答案