Click here to Skip to main content
15,922,309 members
Home / Discussions / Database
   

Database

 
GeneralRe: Recursive Triggers Pin
WoutL22-Oct-04 1:25
WoutL22-Oct-04 1:25 
GeneralSQL query - deleting main row, its related rows, and their related rows Pin
Luis Alonso Ramos21-Oct-04 8:58
Luis Alonso Ramos21-Oct-04 8:58 
GeneralRe: SQL query - deleting main row, its related rows, and their related rows Pin
TimWallace21-Oct-04 9:32
TimWallace21-Oct-04 9:32 
GeneralRe: SQL query - deleting main row, its related rows, and their related rows Pin
Luis Alonso Ramos21-Oct-04 9:53
Luis Alonso Ramos21-Oct-04 9:53 
GeneralADO question Pin
Tom Wright21-Oct-04 5:32
Tom Wright21-Oct-04 5:32 
GeneralDatalist with pages Pin
David Fawn21-Oct-04 5:03
David Fawn21-Oct-04 5:03 
QuestionWhy won't this update to my Database? Pin
fortyonejb21-Oct-04 4:52
fortyonejb21-Oct-04 4:52 
Generalupdating a database in C# Pin
steve_rm21-Oct-04 4:10
steve_rm21-Oct-04 4:10 
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.

When the student returns the book, their studentID number should be cleared from the studentID number in the book table.

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
GeneralVB, ADO, XP - Which one is falling over?! Pin
Pete Belcher20-Oct-04 23:04
Pete Belcher20-Oct-04 23:04 
GeneralRe: VB, ADO, XP - Which one is falling over?! Pin
Michael Potter21-Oct-04 5:05
Michael Potter21-Oct-04 5:05 
GeneralSimple Question on Oracle dbms_utility.get_time Pin
devvvy20-Oct-04 20:34
devvvy20-Oct-04 20:34 
GeneralRe: Simple Question on Oracle dbms_utility.get_time Pin
DiWa20-Oct-04 22:44
DiWa20-Oct-04 22:44 
QuestionDatasets - Totally Stumped - Am I stupid or something? Pin
david@mindplay.com20-Oct-04 12:03
david@mindplay.com20-Oct-04 12:03 
AnswerRe: Datasets - Totally Stumped - Am I stupid or something? Pin
Colin Angus Mackay20-Oct-04 22:00
Colin Angus Mackay20-Oct-04 22:00 
GeneralRe: Datasets - Totally Stumped - Am I stupid or something? Pin
david@mindplay.com21-Oct-04 8:16
david@mindplay.com21-Oct-04 8:16 
GeneralRe: Datasets - Totally Stumped - Am I stupid or something? Pin
Colin Angus Mackay21-Oct-04 11:44
Colin Angus Mackay21-Oct-04 11:44 
GeneralRe: Datasets - Totally Stumped - Am I stupid or something? Pin
david@mindplay.com21-Oct-04 12:11
david@mindplay.com21-Oct-04 12:11 
GeneralRe: Datasets - Totally Stumped - Am I stupid or something? Pin
Colin Angus Mackay21-Oct-04 12:23
Colin Angus Mackay21-Oct-04 12:23 
GeneralRe: Datasets - Totally Stumped - Am I stupid or something? Pin
david@mindplay.com21-Oct-04 12:38
david@mindplay.com21-Oct-04 12:38 
GeneralRe: Datasets - Totally Stumped - Am I stupid or something? Pin
Colin Angus Mackay21-Oct-04 12:45
Colin Angus Mackay21-Oct-04 12:45 
GeneralRe: Datasets - Totally Stumped - Am I stupid or something? Pin
david@mindplay.com21-Oct-04 12:55
david@mindplay.com21-Oct-04 12:55 
GeneralRe: Datasets - Totally Stumped - Am I stupid or something? Pin
Colin Angus Mackay21-Oct-04 11:52
Colin Angus Mackay21-Oct-04 11:52 
GeneralRe: Datasets - Totally Stumped - Am I stupid or something? Pin
david@mindplay.com21-Oct-04 12:22
david@mindplay.com21-Oct-04 12:22 
GeneralRe: Datasets - Totally Stumped - Am I stupid or something? Pin
Colin Angus Mackay21-Oct-04 12:28
Colin Angus Mackay21-Oct-04 12:28 
GeneralRe: Datasets - Totally Stumped - Am I stupid or something? Pin
david@mindplay.com21-Oct-04 12:43
david@mindplay.com21-Oct-04 12:43 

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.