Hi, i have a problem with a small program i wrote which adds vendors to the database. i created a windows form and made it into a dialog that adds vendors to my database. When I open the dialog to add vendors and click add, everything gets saved into the database without any errors, the problem is that even if the entire form is empty and there are some fields like LastName that doesn't allow nulls, the data still gets saved into the database with no problems.
here is the entire code:
The code works fine, its just that it keeps saving data even if there isnt any information in the form.
Thanks to anybody who is willing to help in anyway.
PS: Im using Visual Studio 2008 and SQL Server 2005
here is the entire code:
Code:
Public Sub AddVendor()
StatusLabel.Text = "Creating new vendor"
Dim myAddVendorDialog As New AddVendorDialog()
myAddVendorDialog.VendorNumber = 0
Dim result As DialogResult
result = myAddVendorDialog.ShowDialog
If result = Windows.Forms.DialogResult.OK Then
Try
Dim Vendors As VendorViewDataSet.TBL_VENDORRow
Vendors = myVendorViewDataSet.TBL_VENDOR.NewTBL_VENDORRow
Vendors.LastName = myAddVendorDialog.LastName
Vendors.CompanyName = myAddVendorDialog.CompanyName1
Vendors.PostalCode = myAddVendorDialog.PostalCode
Vendors.FirstName = myAddVendorDialog.FirstName
Vendors.Address = myAddVendorDialog.Address
Vendors.City = myAddVendorDialog.City
Vendors._Region = myAddVendorDialog.Region1
'Vendors.PostalCode = myAddVendorDialog.PostalCode
Vendors.Country = myAddVendorDialog.Country
Vendors.ContactNumber = myAddVendorDialog.ContactNumber
Vendors.Email = myAddVendorDialog.Email
myVendorViewDataSet.TBL_VENDOR.AddTBL_VENDORRow(Vendors)
Dim rowsAffected As Integer = 0
rowsAffected = TbL_VENDORTableAdapter2.Update(Vendors)
If rowsAffected > 0 Then
StatusLabel.Text = "New Vendor - '" & myAddVendorDialog.LastName & "'"
Dim AddAnotherVendor As DialogResult
AddAnotherVendor = MessageBox.Show("No problems encountered. " & _
"Do you want to add another vendor?", "Sucessfull", MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button3)
If AddAnotherVendor = Windows.Forms.DialogResult.Yes Then
Call AddVendor()
Else
AddVendorDialog.Close()
End If
Else
StatusLabel.Text = "Problem creating new Vendor. Could not save into the database."
End If
Catch ex As Exception
MessageBox.Show("Problem creating new Vendor: " & ex.Message)
End Try
Else
StatusLabel.Text = "New Vendor operation cancelled."
End If
myAddVendorDialog = Nothing
End Sub
Thanks to anybody who is willing to help in anyway.
PS: Im using Visual Studio 2008 and SQL Server 2005
Comment