A strange exception

  • Thread starter Thread starter MyCatAlex
  • Start date Start date
M

MyCatAlex

Guest
I have this code:

public void SaveMemoFromEditor (string dataTableName, string numeric_id, string memo)
{
// here we have a totally different situation from the previous: saveMemoFromRtfOthers
if (richTextBox_pg_3.Text != String.Empty)
{
DoServer.GetSrvConnOrSwitch("ComeAndGetThr");
using (SqlConnection conn = new SqlConnection(Globals.srv.ConnectionContext.ConnectionString))
{
conn.Open();
SqlCommand cmdm = new SqlCommand();
cmdm.Connection = conn;
cmdm.CommandType = CommandType.Text;
cmdm.CommandText = "UPDATE [dbo].[" + dataTableName + "] SET memo = @memo WHERE numeric_id = @numeric_id ";
cmdm = SetControls.createSqlParameter(cmdm, "memo", memo);
cmdm = SetControls.createSqlParameter(cmdm, "numeric_id", numeric_id);
cmdm.ExecuteNonQuery(); // <== Exception
} // end of using conn

I get this exception:

System.Data.SqlClient.SqlException
HResult=0x80131904
Message=String or binary data would be truncated.
The statement has been terminated.
Source=.Net SqlClient Data Provider
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
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, TaskCompletionSource`1 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 ComeAndGet.Form1.SaveMemoFromEditor(String dataTableName, String numeric_id, String memo) in C:\VCSharp_Projects\ComeAndGet\ComeAndGet\Form1.cs:line 6412
at ComeAndGet.Form1.pushSaveRTF_pg3_Click(Object sender, EventArgs e) in C:\VCSharp_Projects\ComeAndGet\ComeAndGet\Form1Add5.cs:line 299
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.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 ComeAndGet.Program.Main() in C:\VCSharp_Projects\ComeAndGet\ComeAndGet\Program.cs:line 16

What is this. It is the first time I see something like this.

Thanks, - MyCatAlex

Continue reading...
 
Back
Top