I am having a bit of a weird issue. (WinForms VB.NET)
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:
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.