weird error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • martinmike2
    New Member
    • Jul 2008
    • 3

    weird error

    I am having a bit of a weird issue. (WinForms VB.NET)

    Code:
    Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click
            'Set search parameter SSN
            Dim sInputSSN = InputBox("Please enter a properly formatted SSN.  XXX-XX-XXXX")
    
            'Do connection code
            Dim conn As New SqlClient.SqlConnection
            conn.ConnectionString = connection_string
            Try
                conn.Open()
            Catch ex As Exception
                MessageBox.Show("Database connection error!", gstrAppDlgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
            Dim mycommand As New SqlClient.SqlCommand
            mycommand.Connection = conn
            'Set Query
            mycommand.CommandText = "SELECT * FROM SSN_DATA WHERE SSN LIKE '" & sInputSSN & "'"
            Dim my_da As New SqlClient.SqlDataAdapter
            my_da.SelectCommand = mycommand
            'Execute Query
            Dim MyData As SqlClient.SqlDataReader
            MyData = mycommand.ExecuteReader()
            MyData.Read()
            'Test data
            If MyData.HasRows = False Then
                MessageBox.Show("SSN not valid.  Please contact Manpower.", gstrAppDlgTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Else
                'Move SSN_DATABindSource to found SSN position
                Me.SSN_DATABindingSource.Position = Me.SSN_DATABindingSource.Find("SSN", sInputSSN)
                'Set SSN.ID value into SSN_IDTextBox to set foreign key
                '-SSN_IDTextBox is defaulted to ReadOnly
                Me.SSN_IDTextBox.ReadOnly = False
                '-Set Text property to SSN_DATA.ID value
                Me.SSN_IDTextBox.Text = Me.SSN_MAIN_NOK_DataSet.Tables("SSN_DATA").Rows(Me.SSN_DATABindingSource.Position())("ID")
                '-Reset SSN_IDTextBox to ReadOnly
                Me.SSN_IDTextBox.ReadOnly = True
            End If
    
        End Sub 'AT THIS POINT I GET AN ERROR, SEE ***ERROR*** BELOW
    ***ERROR***
    Column 'SSN_ID' does not allow nulls.
    (This error only occurs after a save a row with data in it(saves fine) then try to add a new row)

    THIS IS MY SAVE CODE:
    Code:
        Private Sub MAIN_DATABindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MAIN_DATABindingNavigatorSaveItem.Click
            Me.Validate()
            Me.MAIN_DATABindingSource1.EndEdit()
            Me.SSN_DATABindingSource.EndEdit()
    
            If Me.txtNOK_SSNID.Text = "" Then
                Me.TableAdapterManager.UpdateAll(Me.SSN_MAIN_NOK_DataSet)
            Else
                Me.NOK_DATABindingSource.EndEdit()
                Me.TableAdapterManager.UpdateAll(Me.SSN_MAIN_NOK_DataSet)
            End If
    
    
        End Sub
    any help would be greatly appreciated.
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    #2
    Which line generates the error? In your code, you state that it's generated on the End Sub, but I think that's not possible. Further, I think the error is pretty clear. 'SSN_ID' does not allow nulls means that you are trying to insert a Null-value in the column SSN_ID and it doesn't allow null-values. There's nothing weird to that...Did you check what value goes in?

    Steven

    Comment

    • martinmike2
      New Member
      • Jul 2008
      • 3

      #3
      this seems to be closed. I'm not sure what I did, to create the error condition, but i ditched the form and re-created it. That seems to have fixed that issue.

      Comment

      Working...