PDA

View Full Version : Visual Basic 2005 & SQL Server Error



CreganTur
02-10-2009, 12:14 PM
I'm working through the Wrox book Visual Basic 2005 Express Edition Starter Kit, and I'm stuck at a point in Chapter 7. Wrox's forums are completely useless, so I am desprately hoping someone here can help me.

The application I've built is a frontend UI that interfaces with a SQL Server database that was created in a seperate project in Visual Basic 2005.

Here's the code that's giving me trouble- explination to follow:

Private Sub LoadListBox()
Dim PersonListAdapter As New _PO_DataDataSetTableAdapters.PersonTableAdapter
Dim PersonListTable As New _PO_DataDataSet.PersonDataTable
PersonListAdapter.Fill(PersonListTable) '<<<Error Here
With lstPersons
.Items.Clear()
.DisplayMember = "DisplayName"
For Each CurrentRow As _PO_DataDataSet.PersonRow In PersonListTable.Rows
Dim CurrentPerson As New Person(CurrentRow.NameFirst, CurrentRow.NameLast)
CurrentPerson.ID = CurrentRow.ID
.Items.Add(CurrentPerson)
Next
End With
End Sub


I'm trying to load a listbox with the values of the NameFirst and NameLast fields in the SQL Server table names Person. The TableAdapter object connects to the database table, and the DataTable object holds the gathered records. This is the EXACT code from the book.

When I run the application in Debug mode and try to load the listbox with the table data I get the error message "Constraint Exception was unhandled: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints." when I try to run this code.

Here's the error's StackTrace. Please let me know if you need any other info:
System.Data.ConstraintException was unhandled
Message="Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."
Source="System.Data"
StackTrace:
at System.Data.DataTable.EnableConstraints()
at System.Data.DataTable.set_EnforceConstraints(Boolean value)
at System.Data.DataTable.EndLoadData()
at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
at System.Data.Common.DataAdapter.Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at Personal_Organizer._PO_DataDataSetTableAdapters.PersonTableAdapter.Fill(Per sonDataTable dataTable) in C:\Visual Studio 2005\Projects\Personal Organizer\Personal Organizer\_PO_DataDataSet.Designer.vb:line 1612
at Personal_Organizer.PersonList.LoadListBox() in C:\Visual Studio 2005\Projects\Personal Organizer\Personal Organizer\PersonList.vb:line 9
at Personal_Organizer.PersonList.PersonList_Load(Object sender, EventArgs e) in C:\Visual Studio 2005\Projects\Personal Organizer\Personal Organizer\PersonList.vb:line 24
at System.Windows.Forms.UserControl.OnLoad(EventArgs e)
at System.Windows.Forms.UserControl.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.ControlCollection.Add(Control value)
at Personal_Organizer.frmMainForm.btnShowList_Click(Object sender, EventArgs e) in C:\Visual Studio 2005\Projects\Personal Organizer\Personal Organizer\MainForm.vb:line 15
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.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.Unsa feNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 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 System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun ()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApp licationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(S tring[] commandLine)
at Personal_Organizer.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()