dcsimg
Results 1 to 15 of 15

Thread: System.ArgumentException: 'Cannot set column 'ort'. The value violates the MaxLength

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2015
    Location
    Hastings, UK
    Posts
    133

    System.ArgumentException: 'Cannot set column 'ort'. The value violates the MaxLength

    I have an exception that dosen't make ant sense to me.
    I have a column in my database that has 'P' for Portrait and 'L' for Landscape, which in the database is a varchar(1).
    Here is the full output message:
    System.ArgumentException: 'Cannot set column 'ort'. The value violates the MaxLength limit of this column.'
    Display
    System.ArgumentException
    HResult=0x80070057
    Message=Cannot set column 'ort'. The value violates the MaxLength limit of this column.
    Source=System.Data
    StackTrace:
    at System.Data.DataColumn.CheckMaxLength(DataRow dr)
    at System.Data.DataTable.RaiseRowChanging(DataRowChangeEventArgs args, DataRow eRow, DataRowAction eAction, Boolean fireEvent)
    at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Boolean suppressEnsurePropertyChanged, Int32 position, Boolean fireEvent, Exception& deferredException)
    at System.Data.DataRow.EndEdit()
    at System.Data.DataRowView.EndEdit()
    at System.Windows.Forms.CurrencyManager.EndCurrentEdit()
    at System.Windows.Forms.CurrencyManager.ChangeRecordState(Int32 newPosition, Boolean validating, Boolean endCurrentEdit, Boolean firePositionChange, Boolean pullData)
    at System.Windows.Forms.CurrencyManager.set_Position(Int32 value)
    at System.Windows.Forms.ComboBox.OnSelectedIndexChanged(EventArgs e)
    at System.Windows.Forms.ComboBox.WmReflectCommand(Message& m)
    at System.Windows.Forms.ComboBox.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.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
    at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m)
    at System.Windows.Forms.Control.WmCommand(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    at System.Windows.Forms.Form.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.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
    at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
    at System.Windows.Forms.Control.DefWndProc(Message& m)
    at System.Windows.Forms.Control.WmCommand(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ComboBox.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.IMsoCompo nentManager.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 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
    at My_Greeting.My.MyApplication.Main(String[] Args) in :line 81
    Why does it say that it excedes the MaxLength limit of this column, as the column is one character wide and only has either the character 'P' or 'L' in the column.
    I don't know if this a clue, but it works upto CID = 9? (Where CID is the ID column and is an int.)
    The last line in the output says line 81, but it isn't the form.vb file. I have seen a file that appears sometimes, that it says you should not edit. How do you view that file?

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,566

    Re: System.ArgumentException: 'Cannot set column 'ort'. The value violates the MaxLen

    There's no need for you to get at line 81 of that Main method. That's simply the entry point for your application and where every call stack starts.

    Given that you have provided us with no code and no way to determine what data is in use, all we can tell you is that, if the error message tells you that the data is too long for the column, the data is too long for the column. You clearly think that you have used appropriate data but, if that were the case, you wouldn't be seeing this error message. Whatever you did, you did it wrong. As you haven't shown us what you did, we can't possibly tell you what's wrong with it, except what the error message is already telling you.

    For the record, it appears that you have a DataTable bound to a ComboBox and the error is being generated when you change the selection in that ComboBox. Its not necessarily the column that is bound to the ComboBox that is at issue though. If you have other controls bound to the same DataTable, changing the selection in the ComboBox will select a different row and thus commit any changes in the other controls to the previous row. If one of those controls contains data that is to long for the column it's bound to, that's the error message you would see. If you're using TextBoxes to edit other columns, for instance, you should set the MaxLength of the TextBoxes so that the user can't enter more data than the corresponding DataColumn can handle.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    33,911

    Re: System.ArgumentException: 'Cannot set column 'ort'. The value violates the MaxLen

    One thing I noted is that 'ort' is the three letters following P in "Portrait". Is that relevant? I can't say. Perhaps you have a column called 'ort' for some reason that eludes me.
    My usual boring signature: Nothing

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,566

    Re: System.ArgumentException: 'Cannot set column 'ort'. The value violates the MaxLen

    Quote Originally Posted by Shaggy Hiker View Post
    One thing I noted is that 'ort' is the three letters following P in "Portrait". Is that relevant? I can't say. Perhaps you have a column called 'ort' for some reason that eludes me.
    I thought that that was a strange column name too but the error message seems to suggest that the column does exist.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2015
    Location
    Hastings, UK
    Posts
    133

    Re: System.ArgumentException: 'Cannot set column 'ort'. The value violates the MaxLen

    Regarding 'Shaggy Hikers' comment: 'ort' was my variable name that represented Orientation. As I stated before in the database it is varchar(1). this column has either P or L in the database.
    I still find it strange that it does not get an exception error until the 10th row and all rows after that?

    As the error to some extent concerns the data table here is a screen shot of the settings:

    Name:  Csize table 11-07-19.png
Views: 54
Size:  6.7 KB
    By the way the float variables are to be used in the future!

    Here is the code for tythe whole form:
    Code:
    Imports PdfSharp
    Imports PdfSharp.Drawing
    Imports PdfSharp.Fonts
    Imports PdfSharp.PageOrientation
    Imports PdfSharp.PageSize
    Imports PdfSharp.Pdf
    Imports PdfSharp.Internal
    Imports PdfSharp.Drawing.Layout
    Imports PdfSharp.Forms
    Imports System.Data.SqlClient
    
    Enum pageOrientation
        Landscape
        Portrait
    End Enum
    Enum pagesize
        A4
        A5
    End Enum
    
    Public Class frmPrintFrm
    
        Private boxX As Double
        Private boxY As Double
        Private cellw As Double
        Private cellh As Double
        Private ort As String = Nothing
        Private FSize As Integer
        Private CFont As String = Nothing
        Private TxtColor As String
        Private sqlAdaptor As SqlDataAdapter
        Private dt As New DataTable
        Private CSizeSql As String = Nothing
        Private cmd As Object = Nothing
        Private CSizeValue As Double
        Private Narrative As String = Nothing
        Private CID As Integer
        Private Y As Double
        Private Verse As String
        Private connectionString As String = "Data Source=DESKTOP-S7FRNAL\SQLEXPRESS;Initial Catalog=Verses_Find;Integrated Security=True"
        Private Sub myBase_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CSizeTableAdapter.Fill(Me.Verses_FindDataSet5.CSize)
            Dim Print As New frmPrintFrm
            Me.TopMost = True
            Me.WindowState = FormWindowState.Normal
    
            For Each oFont As FontFamily In FontFamily.Families 'This line populates the font combo with the system installed fonts
                cboFont.Items.Add(oFont.Name)
            Next
            'fetch the XKnownColor values into cboColor
            Dim knownColours() As XKnownColor = XColorResourceManager.GetKnownColors(includeTransparent:=False)
            cboColor.DataSource = knownColours
            cboColor.SelectedIndex = 0
        End Sub
        Private Sub btnPaste_Click(sender As Object, e As EventArgs) Handles btnPaste.Click
    
            ' Determine if there is any text in the Clipboard to paste into the text box.
            If Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) = True Then
                ' Determine if any text is selected in the text box.
                If txbVerse.SelectionLength > 0 Then
                    ' Ask user if they want to paste over currently selected text.
                    If MessageBox.Show("Do you want to paste over current selection?",
                        "Cut Example", MessageBoxButtons.YesNo) = DialogResult.No Then
                        ' Move selection to the point after the current selection and paste.
                        txbVerse.SelectionStart = txbVerse.SelectionStart + txbVerse.SelectionLength
                    End If
                End If
                ' Paste current text in Clipboard into text box.
                txbVerse.Paste()
            End If
        End Sub
        Private Sub cboCSize_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboCSize.SelectedIndexChanged
            CSizeValue = CInt(cboCSize.SelectedValue)
        End Sub
        Private Sub nudFSize_ValueChanged(sender As Object, e As EventArgs) Handles nudFSize.ValueChanged
            FSize = CInt(nudFSize.Value)
        End Sub
    
        Private Sub cboFont_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboFont.SelectedIndexChanged
            CFont = cboFont.Text
        End Sub
    
        Private Sub nudTop_ValueChanged_1(sender As Object, e As EventArgs) Handles nudTop.ValueChanged
            boxY = CInt(nudTop.Value)
        End Sub
        Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
    
            Using connection As New SqlConnection(connectionString), da As New SqlDataAdapter("SELECT CID, BoxX, Cellw, Cellh, ort, Narrative FROM CSize WHERE CID = @CID", connection), dt As New DataTable
                    connection.Open()
    
                da.SelectCommand.Parameters.AddWithValue("@CID", CSizeValue)
                    da.Fill(dt)
                    If dt.Rows.Count > 0 Then
                        Dim row As DataRow = dt.Rows(0)
                        printIt(row)
    
    
    
                End If
    
            End Using
    
    
        End Sub
        Private Sub printIt(row As DataRow)
            Dim ID As Double = CDbl(row("CID"))
            Dim X As Double = CDbl(row("BoxX")) * 2.83465
            Dim W As Double = CDbl(row("Cellw")) * 2.83465
            Dim H As Double = CDbl(row("Cellh")) * 2.83465
            Dim O As String = CStr(row("ort"))
            Dim N As String = CStr(row("Narrative"))
            Dim Y As Double
            Dim NL As String = CStr(Chr(13) & Chr(10))
            Verse = txbVerse.Text
            Replace(Verse, NL, " VBCrLf ")
            Dim document As PdfDocument
            ' Create a new PDF document
            document = New PdfDocument()
            document.Info.Title = "Created with PDFsharp"
    
            ' Create an empty page
            Dim page As PdfPage = document.AddPage
    
            If O = "L" Then
                page.Orientation = CType(pageOrientation.Landscape, PdfSharp.PageOrientation)
                page.Width = XUnit.FromMillimeter(297)
                page.Height = XUnit.FromMillimeter(210)
            Else
                page.Orientation = CType(pageOrientation.Portrait, PdfSharp.PageOrientation)
                page.Width = XUnit.FromMillimeter(210)
                page.Height = XUnit.FromMillimeter(297)
            End If
    
            '   create the brush
            Dim xClr As XColor = XColor.FromKnownColor(CType(cboColor.SelectedItem, XKnownColor))
            Dim brush As XSolidBrush = New XSolidBrush(xClr)
    
            ' Draw the text
            Y = boxY * 2.834665
    
            Dim gfx As XGraphics
            gfx = XGraphics.FromPdfPage(page)
            Dim tf As XTextFormatter
            tf = New XTextFormatter(gfx)
            Dim font As XFont = New XFont(CFont, FSize, XFontStyle.Regular)
            Dim rect As XRect
            rect = New XRect(X, Y, W, H)
            gfx.DrawRectangle(XBrushes.SeaShell, rect)
            tf.Alignment = XParagraphAlignment.Center
            tf.DrawString(Verse, font, brush, rect, XStringFormat.TopLeft)
    
            ' Save the document
            Dim filename As String = "verse.pdf"
            document.Save(filename)
    
            ' ...and start a viewer.
            Process.Start(filename)
            Me.Close()
        End Sub
    End Class
    Does this information help solve the problem?

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,566

    Re: System.ArgumentException: 'Cannot set column 'ort'. The value violates the MaxLen

    Quote Originally Posted by Rocky48 View Post
    Regarding 'Shaggy Hikers' comment: 'ort' was my variable name that represented Orientation.
    That really bugs me. Why not just name it 'Orientation'? We're not writing code in Notepad any more. Abbreviations like that are a waste of time.

    Also, what's up with your complete indifference to the casing of the first letter of your columns and fields? That's just bad.
    Quote Originally Posted by Rocky48 View Post
    I still find it strange that it does not get an exception error until the 10th row and all rows after that?
    So have you debugged the code and examined the data to see what the difference is? You don't just read the code to solve issues like this. You use the debugger that Microsoft has so kindly integrated in the development environment to watch the code and the application state as it executes.

  7. #7
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,147

    Re: System.ArgumentException: 'Cannot set column 'ort'. The value violates the MaxLen

    Why don't you help us out and tell us what line of code is causing the error.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Dec 2015
    Location
    Hastings, UK
    Posts
    133

    Re: System.ArgumentException: 'Cannot set column 'ort'. The value violates the MaxLen

    Sorry I am not that experienced in debugging, but have just put a break point at the sub to select the CSize (Card Size).
    I did this firstly, with a selection that I knew would work and observed what happened when I stepped thro the sub. Although I made a selection it returned to the first item in the list, until I stepped out of the sub and I continued stepping until the PDF file opened in Adobe.
    I then selected a card size which I knew would fail. This did the same, except when I stepped out of the sub, the exception error occured.
    The combobox is set using the combo controls and the Selected Value is set as 'ort' (See screen shot)
    Attachment 169771
    I'm still puzzled why it only fails on the 10th or greater value of CID. As you can see it's set as primary key and is an int from the screenshot in the previous post (#5).
    This is the sub that the exception occured:
    Code:
    Private Sub cboCSize_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboCSize.SelectedIndexChanged
            CSizeValue = CInt(cboCSize.SelectedValue)
        End Sub
    Can anyone spot why it fails?
    I have also attached the sql file for CSize.
    Code:
    CID	BoxX	Cellw	Cellh	Size	floatx	floaty	floatw	floath	ort	Narrative
    1	162.8	120	10	A5P	148.5	0	148	210	L	A5 Portrait
    2	46	120	10	A5L	0	150	210	148	P	A5 Landscape
    3	12	102	10	A5PS	0	0	148	210	L	A5 Portrait Single
    4	120	76	10	A6P	105	0	104	147	P	A6 Portrait
    5	24	100	10	A6L	0	105	147	104	L	A6 Landscape
    6	3	100	10	A6PS	0	0	104	147	P	A6 Portrait Single
    7	112	70	10	DLP	100	0	99	210	P	DL Portrait
    8	45	120	10	DLL	0	100	210	99	P	DL Landscape
    9	18	120	10	6X4L	0	102	152	101	P	6 x 4ins Landscape
    10	117.4	70	10	6X4P	101.6	0	101	152	L	6 x 4ins Portrait
    11	29	120	10	7X5L	0	128	178	127	P	7 x 5ins Landscape
    12	138	108	10	7X5P	128	0	127	178	L	7 x 5ins Portrait
    13	4	110	10	120SQL	0	121	120	120	P	120mm Square Landscape
    14	125	110	10	120SQP	121	0	120	120	L	120mm Square Portrait
    15	8	110	10	125SQL	0	126	125	125	P	125mm Square Landscape
    16	127	120	10	125SQP	126	0	125	125	L	125mm Square Portrait
    17	4	120	10	130SQL	0	131	130	130	P	130mm Square Landscape
    18	137	120	10	130SQP	131	0	130	130	L	130mm Square Portrait
    19	12	110	10	135SQL	0	136	135	135	P	135mm Square Landscape
    20	148	110	10	135SQP	136	0	135	135	L	135mm Square Portrait
    21	120	76	10	140X102P	106	0	102	140	P	140 x 102mm Portrait
    22	138	76	10	140X115P	116	0	115	140	L	140 x 115mm Portrait
    23	17	110	10	145SQL	0	146	145	145	P	145mm Square Landscape
    24	163	110	10	145SQP	146	0	145	145	L	145mm Square Portrait
    25	19	110	10	150SQL	0	151	150	150	P	150mm Square Landscape
    26	168	110	10	150SQP	149	0	149	149	L	150mm Square Portrait
    27	105	76	10	150X95P	96	0	95	150	L	150 x 95mm Portrait
    28	135	76	10	150X115P	116	0	115	150	L	150 x 115mm Portrait
    29	24	110	10	160SQS	0	0	160	160	P	160mm Square Single
    30	42	76	10	160X115L	0	116	160	115	P	160 x 115mm Landscape
    31	135	76	10	160X115P	116	0	115	160	L	160 x 115mm Portrait
    32	47	76	10	170X115L	0	116	170	115	P	170 x 115mm Landscape
    33	135	76	10	170X115P	116	0	115	170	L	170 x 115mm Portrait
    34	150	76	10	170X125P	126	0	125	170	L	170 x 125mm Portrait
    35	35	120	10	190SQS	0	0	190	190	P	190mm Square Single
    36	135	76	10	190X115P	116	0	115	190	L	190 x 115mm Portrait
    37	157	76	10	190X130P	131	0	130	190	L	190 x 130mm Portrait
    38	40	120	10	200SQS	0	0	200	200	P	200mm Square Single
    39	45	120	10	210SQS	0	0	210	210	P	210mm Square Single
    40	157	76	10	210X130	131	0	130	210	L	210 x 130mm Portrait
    41	157	110	10	140SQP	140	0	140	140	L	140mm Square Portrait
    42	17	110	10	140SQL	0	140	140	140	P	140mm Square Landscape
    43	106	76	10	140x95P	96	0	95	140	L	140 x 95mm Portrait
    44	16	110	10	140x95L	0	96	140	95	P	140 x 95 Landscape
    45	33	110	10	7inSQS	0	0	176	176	L	7ins Square Single
    46	162	120	10	148SQP	148	0	148	148	L	148mm SQ Portrait

  9. #9
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,147

    Re: System.ArgumentException: 'Cannot set column 'ort'. The value violates the MaxLen

    Your attachment link doesn't work. Some of your values in ort are more one character. So I'm not sure how that's possible if the field is defined with a maxlength of one.

    Still don't know the exact line of code causing the problem, when the error occurs what line of code does it stop at??

    The fact that error occurs when CID reaches 10 or higher makes me notice that 10 and above have a length of 2 or greater. But what that has to do with ort, I have no idea. What are the properties of that ComboBox, DisplayMember, ValueMember, Datasource.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Dec 2015
    Location
    Hastings, UK
    Posts
    133

    Re: System.ArgumentException: 'Cannot set column 'ort'. The value violates the MaxLen

    Sorry I am not that experienced in debugging, but have just put a break point at the sub to select the CSize (Card Size).
    I did this firstly, with a selection that I knew would work and observed what happened when I stepped thro the sub. Although I made a selection it returned to the first item in the list, until I stepped out of the sub and I continued stepping until the PDF file opened in Adobe.
    I then selected a card size which I knew would fail. This did the same, except when I stepped out of the sub, the exception error occured.
    The combobox is set using the combo controls and the Selected Value is set as 'ort' (See screen shot)
    Attachment 169771
    I'm still puzzled why it only fails on the 10th or greater value of CID. As you can see it's set as primary key and is an int from the screenshot in the previous post (#5).
    This is the sub that the exception occured:
    Code:
    Private Sub cboCSize_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboCSize.SelectedIndexChanged
            CSizeValue = CInt(cboCSize.SelectedValue)
        End Sub
    Can anyone spot why it fails?
    I have also attached the sql file for CSize.
    Code:
    CID	BoxX	Cellw	Cellh	Size	floatx	floaty	floatw	floath	ort	Narrative
    1	162.8	120	10	A5P	148.5	0	148	210	L	A5 Portrait
    2	46	120	10	A5L	0	150	210	148	P	A5 Landscape
    3	12	102	10	A5PS	0	0	148	210	L	A5 Portrait Single
    4	120	76	10	A6P	105	0	104	147	P	A6 Portrait
    5	24	100	10	A6L	0	105	147	104	L	A6 Landscape
    6	3	100	10	A6PS	0	0	104	147	P	A6 Portrait Single
    7	112	70	10	DLP	100	0	99	210	P	DL Portrait
    8	45	120	10	DLL	0	100	210	99	P	DL Landscape
    9	18	120	10	6X4L	0	102	152	101	P	6 x 4ins Landscape
    10	117.4	70	10	6X4P	101.6	0	101	152	L	6 x 4ins Portrait
    11	29	120	10	7X5L	0	128	178	127	P	7 x 5ins Landscape
    12	138	108	10	7X5P	128	0	127	178	L	7 x 5ins Portrait
    13	4	110	10	120SQL	0	121	120	120	P	120mm Square Landscape
    14	125	110	10	120SQP	121	0	120	120	L	120mm Square Portrait
    15	8	110	10	125SQL	0	126	125	125	P	125mm Square Landscape
    16	127	120	10	125SQP	126	0	125	125	L	125mm Square Portrait
    17	4	120	10	130SQL	0	131	130	130	P	130mm Square Landscape
    18	137	120	10	130SQP	131	0	130	130	L	130mm Square Portrait
    19	12	110	10	135SQL	0	136	135	135	P	135mm Square Landscape
    20	148	110	10	135SQP	136	0	135	135	L	135mm Square Portrait
    21	120	76	10	140X102P	106	0	102	140	P	140 x 102mm Portrait
    22	138	76	10	140X115P	116	0	115	140	L	140 x 115mm Portrait
    23	17	110	10	145SQL	0	146	145	145	P	145mm Square Landscape
    24	163	110	10	145SQP	146	0	145	145	L	145mm Square Portrait
    25	19	110	10	150SQL	0	151	150	150	P	150mm Square Landscape
    26	168	110	10	150SQP	149	0	149	149	L	150mm Square Portrait
    27	105	76	10	150X95P	96	0	95	150	L	150 x 95mm Portrait
    28	135	76	10	150X115P	116	0	115	150	L	150 x 115mm Portrait
    29	24	110	10	160SQS	0	0	160	160	P	160mm Square Single
    30	42	76	10	160X115L	0	116	160	115	P	160 x 115mm Landscape
    31	135	76	10	160X115P	116	0	115	160	L	160 x 115mm Portrait
    32	47	76	10	170X115L	0	116	170	115	P	170 x 115mm Landscape
    33	135	76	10	170X115P	116	0	115	170	L	170 x 115mm Portrait
    34	150	76	10	170X125P	126	0	125	170	L	170 x 125mm Portrait
    35	35	120	10	190SQS	0	0	190	190	P	190mm Square Single
    36	135	76	10	190X115P	116	0	115	190	L	190 x 115mm Portrait
    37	157	76	10	190X130P	131	0	130	190	L	190 x 130mm Portrait
    38	40	120	10	200SQS	0	0	200	200	P	200mm Square Single
    39	45	120	10	210SQS	0	0	210	210	P	210mm Square Single
    40	157	76	10	210X130	131	0	130	210	L	210 x 130mm Portrait
    41	157	110	10	140SQP	140	0	140	140	L	140mm Square Portrait
    42	17	110	10	140SQL	0	140	140	140	P	140mm Square Landscape
    43	106	76	10	140x95P	96	0	95	140	L	140 x 95mm Portrait
    44	16	110	10	140x95L	0	96	140	95	P	140 x 95 Landscape
    45	33	110	10	7inSQS	0	0	176	176	L	7ins Square Single
    46	162	120	10	148SQP	148	0	148	148	L	148mm SQ Portrait

  11. #11
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    33,911

    Re: System.ArgumentException: 'Cannot set column 'ort'. The value violates the MaxLen

    Well, there's something wrong with that file you are showing, though it seems unrelated. I see several lines that are shifted one column to the right starting with the floatx column. That looks like just a display issue when the value in the Size field gets too large for the space it has. Doesn't seem related because it doesn't happen on row 10.

    I have never seen or used the form you show in the screenshot. I'm particularly unsure about the final drop down in that form. That's where you mention ort, as the selected value, but that doesn't seem right. The value member is CID, as you have it in the form. I note that you say that this is crashing as soon as you get to a CID that is two characters long, and for every other case where CID is two characters long, and the crash is complaining about getting a value that is longer than one character. That certainly seems suggestive.

    What I don't see in the code is where CSizeValue is used. I see that it is declared (incorrectly, too, because it clearly can only be an Integer, yet you have given it type Double), but I don't see it being used anywhere other than the line where it was set.

    So, without having ever seen the form in the screenshot, I'd get rid of what you have in SelectedValue unless you can clearly articulate what that is for and why it has to be set the way you have it set. Second, where is CSizeValue being used? I don't see it, but it sure looks like it might be the culprit, because as soon as that becomes two characters, you end up with an error about a value being too large for a one character field.
    My usual boring signature: Nothing

  12. #12
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,243

    Re: System.ArgumentException: 'Cannot set column 'ort'. The value violates the MaxLen

    @Shaggy Hiker: CDizeValue is being used in btnPrint_Click:
    Code:
    Using connection As New SqlConnection(connectionString),
                          da As New SqlDataAdapter("SELECT CID, BoxX, Cellw, Cellh, ort, Narrative FROM CSize WHERE CID = @CID", connection),
                          dt As New DataTable 
            connection.Open()                                                                                                                      
                                                                                                                                                   
        da.SelectCommand.Parameters.AddWithValue("@CID", CSizeValue)                                                                               
            da.Fill(dt)


    @Rocky:
    As Shaggy says, make sure the Selected Value drop down in the ComboBox Tasks window is set to None

    You have a TableAdapter which loads data from the database into your CSize table. The CSize table is the DataSource for a BindingSource (CSizeBindingSource) which is itself the DataSource for the ComboBox.

    Setting the Selected Value to 'ort' in the ComboBox Tasks window sets up a data binding between the ComboBox's selected value (the integer values in the CId column) and the 'ort' column of the CSize DataTable . Every time you select an item in the ComboBox, the value of CId is being automatically written to the ort column, overwriting the L's and P's, and "10" is 2 characters so won't fit in a varchar(1).

    BTW, looking at the table data you posted above, the L and P values in the 'ort' column don't appear to match the values in the 'Narrative' column.

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Dec 2015
    Location
    Hastings, UK
    Posts
    133

    Re: System.ArgumentException: 'Cannot set column 'ort'. The value violates the MaxLen

    Regarding the last comment, there is nothing wrong there!
    If you think of a greeting card insert, lets say A5 size and is a portrait type, the insert inside would have to be printed as Landscape.

    Thinking about the statements you made above, I changed the CSizeValue to ValueMember (CID) and the Selected Value also to CID (I wanted to change it to None, but it won't let me).
    In the code for the Combo I changed CSizeValue to CID
    Code:
     CID = cboCSize.ValueMember
    At the top of the btnPrint sub, I tried to change the type to Integer, but I get a format error, can't change string to integer.
    Code:
    Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
            CSizeValue = CType(CID, Integer)
            Using connection As New SqlConnection(connectionString), da As New SqlDataAdapter("SELECT CID, BoxX, Cellw, Cellh, ort, Narrative FROM CSize WHERE CID = @CID", connection), dt As New DataTable
                    connection.Open()
    How do I get around this, because obviously CID is an Integer?

  14. #14
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,243

    Re: System.ArgumentException: 'Cannot set column 'ort'. The value violates the MaxLen

    Quote Originally Posted by Rocky48 View Post
    Regarding the last comment, there is nothing wrong there!
    If you think of a greeting card insert, lets say A5 size and is a portrait type, the insert inside would have to be printed as Landscape.
    OK. I've never found portrait/landscape settings to be intuitive, so I'll have to take your word for that. :-)


    I don't know what you mean by:
    Quote Originally Posted by Rocky48 View Post
    I changed the CSizeValue to ValueMember (CID)and the Selected Value also to CID
    so I'll assume you mean you changed the ValueMember Property of the cboCSize ComboBox to "CID", and also the 'Selected Value' drop down in the ComboBox Tasks window to "CID". Ideally you want None in that drop down, but you say:
    Quote Originally Posted by Rocky48 View Post
    (I wanted to change it to None, but it won't let me).
    I don't know why it won't let you change it. I'm not seeing that problem:

    Name:  ort to None.png
Views: 36
Size:  18.4 KB


    Quote Originally Posted by Rocky48 View Post
    In the code for the Combo I changed CSizeValue to CID
    Code:
     CID = cboCSize.ValueMember
    At the top of the btnPrint sub, I tried to change the type to Integer, but I get a format error, can't change string to integer.
    OK. So you substituted the variable CID for the variable CSizeValue in that Sub. You must also have changed the declaration of the CID variable to As String, as you originally had it as Private CID As Integer, and that would have caused an error in the above line of code because cboCSize.ValueMember returns a String.

    You are still mixing up ValueMember and SelectedValue.
    cboCSize.ValueMember returns the name of the column in the CSize Table that the ComboBox uses for the values of its Items (not to be confused with what is actually displayed in the ComboBox). Again, you could easily confirm this by placing a break point on that line and then hovering your mouse over 'ValueMember' when code execution stops at the break point:

    Name:  Debug ValueMember.jpg
Views: 35
Size:  11.7 KB


    And that's also why you get your error at the top of the btnPrint Sub: the value "CID" can't be converted to an integer.


    Quote Originally Posted by Rocky48 View Post
    How do I get around this, because obviously CID is an Integer?
    Make sure the CB's ValueMember Property is set to "CID", and that the CID variable is declared As Integer. Then change the code in the cboCSize_SelectedIndexChanged Sub back to
    Code:
     CID = CInt(cboCSize.SelectedValue)
    Last edited by Inferrd; Jul 12th, 2019 at 06:20 AM. Reason: forgot to CInt

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Dec 2015
    Location
    Hastings, UK
    Posts
    133

    Re: System.ArgumentException: 'Cannot set column 'ort'. The value violates the MaxLen

    Thank you Iferred
    You explained it so my febble mind could understand.
    At 71 I hope I've got a few more years of programming.
    The program is now working correctly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width