Click here to Skip to main content
16,016,067 members
Home / Discussions / C#
   

C#

 
GeneralRe: run .net app in all systems Pin
Heath Stewart21-Oct-04 7:14
protectorHeath Stewart21-Oct-04 7:14 
GeneralRe: run .net app in all systems Pin
McClamm21-Oct-04 9:01
McClamm21-Oct-04 9:01 
GeneralRe: run .net app in all systems Pin
Heath Stewart21-Oct-04 13:42
protectorHeath Stewart21-Oct-04 13:42 
Generaldatagrid column sorting Pin
ddelapasse21-Oct-04 4:35
ddelapasse21-Oct-04 4:35 
GeneralAdd-In VS .NET 2003 ToolTip on Words in Editor Pin
Nxsis21-Oct-04 3:46
Nxsis21-Oct-04 3:46 
GeneralRe: Add-In VS .NET 2003 ToolTip on Words in Editor Pin
Heath Stewart21-Oct-04 7:20
protectorHeath Stewart21-Oct-04 7:20 
GeneralRe: Add-In VS .NET 2003 ToolTip on Words in Editor Pin
Anonymous21-Oct-04 7:48
Anonymous21-Oct-04 7:48 
Generalupdating a database Pin
steve_rm21-Oct-04 2:58
steve_rm21-Oct-04 2:58 
Hello,

I am developing a library system. I have 2 tables, book and student. The relationship is 1 student can have many books. I am having updating the book table when the student returns the book, the studentID (foreign key) will be cleared from the book table. I think this is the problem l am having. My code is listed below with the error description.

try<br />
			{<br />
				cnnReturnBook.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\IBS Library System\LibrarySystem.mdb;Persist Security Info=False";<br />
			<br />
				//Find the book that have to be returned<br />
				OleDbCommand cmdReturnBook = cnnReturnBook.CreateCommand();<br />
				cmdReturnBook.CommandText = @"SELECT * FROM BOOK<br />
											  WHERE RefNumber = '" + txtBookRef.Text + "' ";<br />
<br />
				OleDbDataAdapter daReturnBook = new OleDbDataAdapter(cmdReturnBook);<br />
				OleDbCommandBuilder cbReturnBook = new OleDbCommandBuilder(daReturnBook);<br />
<br />
				if ( daReturnBook.Fill(dtReturnBook) == 1 )//Book has been found, there should be only one 1 record in the datatable<br />
				{<br />
					//Clear the text boxes<br />
					txtDateOut.Text = "";<br />
					txtDateDue.Text = "";<br />
					txtStatus.Text = "Available"; //Show that the book is now available<br />
					txtIDNumber.Text = ""; //ID number of the student who has this book.<br />
					txtName.Text = "";<br />
					txtSurname.Text = "";<br />
<br />
					//Insert into the datatable row the new values<br />
					dtReturnBook.Rows[0]["Status"] = txtStatus.Text;<br />
					dtReturnBook.Rows[0]["DateOut"] = txtDateOut.Text;<br />
					dtReturnBook.Rows[0]["Remarks"] = txtRemarks.Text;<br />
					dtReturnBook.Rows[0]["StudentID"] = txtIDNumber.Text;<br />
					dtReturnBook.Rows[0]["DateDue"] = txtDateDue.Text;<br />
<br />
					daReturnBook.Update(dtReturnBook);//Error here<br />
				}<br />
			}<br />
			catch ( OleDbException ex )<br />
			{<br />
				MessageBox.Show(ex.ToString(),"Exeception has occurred",MessageBoxButtons.OK,MessageBoxIcon.Warning);<br />
			}<br />
			catch ( Exception ex )<br />
			{<br />
				MessageBox.Show(ex.ToString(),"Exeception has occurred",MessageBoxButtons.OK, MessageBoxIcon.Warning);<br />
			}<br />
			finally <br />
			{<br />
				cnnReturnBook.Dispose();<br />
			}<br />
		}


Error description
System.Data.OleDb.OleDbException: You cannot add or change a record because a related record is required in table 'Student'.
At System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
At System.Data.Common.DbDataAdapter.Update(DataTable dataTable)

Thanks in advance,

Steve
GeneralRe: updating a database Pin
Hugo Hallman21-Oct-04 3:03
Hugo Hallman21-Oct-04 3:03 
GeneralRe: updating a database Pin
Colin Angus Mackay21-Oct-04 3:11
Colin Angus Mackay21-Oct-04 3:11 
GeneralRe: updating a database Pin
steve_rm21-Oct-04 3:53
steve_rm21-Oct-04 3:53 
GeneralRe: updating a database Pin
Colin Angus Mackay21-Oct-04 5:02
Colin Angus Mackay21-Oct-04 5:02 
QuestionHigh performance buffer pooling? Pin
Hugo Hallman21-Oct-04 2:40
Hugo Hallman21-Oct-04 2:40 
AnswerRe: High performance buffer pooling? Pin
Heath Stewart21-Oct-04 7:41
protectorHeath Stewart21-Oct-04 7:41 
GeneralScrollBar Problem Pin
ee9903521-Oct-04 2:07
ee9903521-Oct-04 2:07 
GeneralRe: ScrollBar Problem Pin
Heath Stewart21-Oct-04 7:26
protectorHeath Stewart21-Oct-04 7:26 
GeneralRe: ScrollBar Problem Pin
ee9903521-Oct-04 8:46
ee9903521-Oct-04 8:46 
GeneralRe: ScrollBar Problem Pin
Heath Stewart21-Oct-04 9:07
protectorHeath Stewart21-Oct-04 9:07 
GeneralChanging the Form icon Pin
Tony D. Abel21-Oct-04 2:03
Tony D. Abel21-Oct-04 2:03 
GeneralRe: Changing the Form icon Pin
perlmunger21-Oct-04 7:16
perlmunger21-Oct-04 7:16 
GeneralRe: Changing the Form icon Pin
Tony D. Abel22-Oct-04 5:36
Tony D. Abel22-Oct-04 5:36 
GeneralRegister Window Message Pin
ppp00121-Oct-04 1:42
ppp00121-Oct-04 1:42 
QuestionHow to find the window handle of MessageWindow instance of C# compact framework? Pin
ting66821-Oct-04 1:41
ting66821-Oct-04 1:41 
Generalcreate COM in c# Pin
ppp00121-Oct-04 1:32
ppp00121-Oct-04 1:32 
GeneralRe: create COM in c# Pin
perlmunger21-Oct-04 7:02
perlmunger21-Oct-04 7:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.