Results 1 to 5 of 5

Thread: How to catch this exception? [2003]

  1. #1

    Thread Starter
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    How to catch this exception? [2003]

    Tricky one. I downloaded this project from MSDN, DownloadManagerRefactored. I needed it because I need to display ComboBoxes in a datagrid.

    Things are great except I am unable to edit my textboxes when the dataGrid is set to Readonly. So fine I set the dataGrid to ReadOnly = False, but then I get the new and blank record. This is what messes me up. If I click anywhere on the new record, I get an untrappable error (see pic).

    This is no good because even though I can kind of "hide" it, the user can still hit the [Enter] key while editing the last row and that sets focus on the last row and the same thing happens.

    I may be able to trap the columns under the Labal and/or ComboBox, but not the TextBox. I can upload the project but you won't be able to see it in action because it is database driven. I can post the main code that sets it up:

    VB Code:
    1. Private Sub BindControls()
    2.  
    3.             Dim strTestName As String
    4.             Dim strColumnName As String
    5.             Dim intColumntype As Integer
    6.             Dim i As Integer
    7.             Dim strCol As String
    8.             Dim strDropdownValue As String
    9.             Dim strSerialNumber As String
    10.  
    11.             Dim strCol1 As String
    12.             Dim strCol2 As String
    13.             Dim strCol3 As String
    14.  
    15.             MyConnection = New SqlConnection
    16.             MyConnection.ConnectionString = cmbxSQLConnectionString.Text
    17.             MyConnection.Open()
    18.  
    19.             MyCommand = New SqlCommand("spIASGetTest", MyConnection)
    20.             MyCommand.CommandType = CommandType.StoredProcedure
    21.             MyCommand.Parameters.Add("@testName", SqlDbType.VarChar).Value = cmbxLabTests.Text
    22.             MyDataReader = MyCommand.ExecuteReader()
    23.  
    24.             Dim dmTable As New DataTable
    25.  
    26.             If MyDataReader.HasRows Then
    27.                 '
    28.                 While (MyDataReader.Read())
    29.                     '
    30.                     strTestName = MyDataReader.Item("Test Name")
    31.                     strColumnName = MyDataReader.Item("columnName")
    32.                     '
    33.                     dmTable.Columns.Add(New DataColumn(strColumnName, GetType(String)))
    34.                     '
    35.                 End While
    36.                 '
    37.             End If
    38.             '
    39.             MyDataReader.Close()
    40.  
    41.             Dim dst As New DataGridTableStyle
    42.  
    43.             dmTable.TableName = strTestName
    44.             dst.MappingName = strTestName
    45.  
    46.             ' Sample No
    47.             strCol1 = dmTable.Columns.Item(0).ToString
    48.             Dim dglcSampleNo As New DataGridLabelColumn
    49.             dglcSampleNo.MappingName = strCol1
    50.             dglcSampleNo.HeaderText = strCol1
    51.             dst.GridColumnStyles.Add(dglcSampleNo)
    52.             '
    53.             '
    54.             Dim dgcbc As DataGridComboBoxColumn
    55.             Dim dgtbc As DataGridTextBoxColumn
    56.  
    57.             For i = 1 To dmTable.Columns.Count - 1
    58.                 '
    59.                 strCol = dmTable.Columns.Item(i).ToString
    60.                 '
    61.                 MyCommand = New SqlCommand("spIASGetDropDown", MyConnection)
    62.                 MyCommand.CommandType = CommandType.StoredProcedure
    63.                 MyCommand.Parameters.Add("@testName", SqlDbType.VarChar).Value = strTestName
    64.                 MyCommand.Parameters.Add("@columnName", SqlDbType.VarChar).Value = strCol
    65.                 '
    66.                 MyDataReader = MyCommand.ExecuteReader()
    67.                 '
    68.                 If MyDataReader.HasRows Then
    69.                     '
    70.                     dgcbc = New DataGridComboBoxColumn
    71.                     dgcbc.MappingName = strCol
    72.                     dgcbc.HeaderText = strCol
    73.                     '
    74.                     dgcbc.Add("")
    75.                     '
    76.                     While (MyDataReader.Read())
    77.                         strDropdownValue = MyDataReader.Item("dropDownString")
    78.                         dgcbc.Add(strDropdownValue)
    79.                     End While
    80.                     '
    81.                     dst.GridColumnStyles.Add(dgcbc)
    82.                     '
    83.                 Else
    84.                     dgtbc = New DataGridTextBoxColumn
    85.                     dgtbc.MappingName = strCol
    86.                     dgtbc.HeaderText = strCol
    87.                     dst.GridColumnStyles.Add(dgtbc)
    88.                End If
    89.                 '
    90.                 MyDataReader.Close()
    91.                 '
    92.             Next
    93.  
    94.             MyCommand = New SqlCommand("spIASGetSerialNumbers", MyConnection)
    95.             MyCommand.CommandType = CommandType.StoredProcedure
    96.             MyCommand.Parameters.Add("@projectName", SqlDbType.VarChar).Value = Me.txtProject.Text
    97.             MyDataReader = MyCommand.ExecuteReader()
    98.  
    99.             Dim dr As DataRow
    100.  
    101.             If MyDataReader.HasRows Then
    102.                 '
    103.                 While (MyDataReader.Read())
    104.                     '
    105.                     strSerialNumber = MyDataReader.Item("serialNumber")
    106.                     '
    107.                     dr = dmTable.NewRow()
    108.                     '
    109.                     strCol1 = dmTable.Columns.Item(0).ToString
    110.                     dr(strCol1) = strSerialNumber
    111.                     '
    112.                     For i = 1 To dmTable.Columns.Count - 1
    113.                         strCol = dmTable.Columns.Item(i).ToString
    114.                         dr(strCol) = "0"
    115.                     Next
    116.                     '
    117.                     dmTable.Rows.Add(dr)
    118.                     '
    119.                 End While
    120.                 '
    121.             End If
    122.  
    123.             dataGrid.TableStyles.Add(dst)
    124.             dataGrid.DataSource = dmTable
    125.             dataGrid.ReadOnly = False
    126.  
    127.         End Sub
    Attached Images Attached Images  
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: How to catch this exception? [2003]

    The problem is just like it says... you can't insert a NULL value when the table is expecting a number.... presumably it's one of the dropdown you've got there that's expecting a number, only nothing was sleected, so it tried to insert a NULL value instead....only that doesn't work.
    You'll need to look to see what events fire off when... see if there's a before move, or something that fires before actually moving to a new row. From there you should be able to see everything going on, and validate your data before moving to the new row.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: How to catch this exception? [2003]

    Nothing is wrong with the row that has values. The problem is I cannot trap this error - to find out exactly where it is occuring.

    See the attached pic. The debugger sends me to the line of code "Public Class Mainform". I have stepped through almost all the dataGrid's events. Anything I do doesnt seem to matter. The debugger still sends me to that same line of code.

    How can I "Try/Catch" that line of code?
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  4. #4
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    Re: How to catch this exception? [2003]

    Get an Application events file (from the project menu if you want).
    The application event file has 4 (or 5) events that related to app startup, shutdown, and any exception thats thrown which is not handled.

    Put your code there (if you want to messagebox it, or if you want to ignore it).
    Note if you do choose to ignore it, an exception that occurs in any other part of the program (which is not handled by try/catch) will also be ignored.

  5. #5

    Thread Starter
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: How to catch this exception? [2003]

    Masfenix, how do I see or get this file? Thanks!
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

Posting Permissions

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



Click Here to Expand Forum to Full Width