Click here to Skip to main content
15,914,322 members
Home / Discussions / C#
   

C#

 
GeneralRe: regex guru pls Pin
User 665825-Jun-05 5:27
User 665825-Jun-05 5:27 
GeneralRe: regex guru pls Pin
g00fyman25-Jun-05 14:25
g00fyman25-Jun-05 14:25 
GeneralAlways search before you ask please Pin
DavidNohejl25-Jun-05 14:52
DavidNohejl25-Jun-05 14:52 
GeneralRe: Always search before you ask please Pin
g00fyman25-Jun-05 15:00
g00fyman25-Jun-05 15:00 
GeneralRe: Always search before you ask please Pin
DavidNohejl25-Jun-05 15:13
DavidNohejl25-Jun-05 15:13 
GeneralRe: Always search before you ask please Pin
g00fyman25-Jun-05 15:26
g00fyman25-Jun-05 15:26 
GeneralSend common files to printer Pin
DukeII25-Jun-05 2:15
DukeII25-Jun-05 2:15 
Generalupdating a dataset Pin
steve_rm24-Jun-05 23:59
steve_rm24-Jun-05 23:59 
Hello,

When l got to update my database l get this error message "Missing the datacolumn 'DepartmentName' in the DataTable 'Employee' for the sourceColumn 'DepartmentName' ".

I have a database application. 2 tables. Department and Employee.
Department -> DepartmentCode (PK)
DepartmentName

Employee -> EmployeeID (PK)
Name
Surname
DepartmentCode (FK)

I have create this relationship in code using relationships in the form load event. see below:
<br />
private void frmEmployees_Load(object sender, System.EventArgs e)<br />
		{<br />
			try<br />
			{<br />
				cnn.Open();<br />
				//Fill the DataSet with the Employee details<br />
				OleDbCommand cmd = cnn.CreateCommand();<br />
				cmd.CommandType = CommandType.Text;<br />
				cmd.CommandText = "SELECT * FROM Employee";<br />
				da.SelectCommand = cmd;<br />
				//Gets all the details for the database, e.g. Primary keys<br />
				da.FillSchema(ds,SchemaType.Source,"Employee");<br />
				da.Fill(ds,"Employee");<br />
				<br />
				//Fill the DataSet wtih the Department details<br />
				cmd.CommandText = "SELECT * FROM Department";<br />
				da.SelectCommand = cmd;<br />
				da.FillSchema(ds,SchemaType.Source,"Department");<br />
				da.Fill(ds,"Department");<br />
				<br />
				//Assign the parent column of the Department table and child column of the<br />
				//employee table. Remember - DepartmentCode PK in Department table, and <br />
				//FK in the Employee Table.<br />
				DataColumn parentColumn = ds.Tables["Department"].Columns["DepartmentCode"];<br />
				DataColumn childColumn = ds.Tables["Employee"].Columns["DepartmentCode"];<br />
				<br />
				//Clear the relation of any data. Not really nessessary as we are creating from new.<br />
				//However, if we are to reuse then we must clear all contents.<br />
				ds.Relations.Clear();<br />
				drEmployees = new DataRelation("EmployeeDetails",parentColumn,childColumn);<br />
				ds.Relations.Add(drEmployees);<br />
				<br />
				//Display the details of the first employee in the database.<br />
				txtEmployeeID.Text = ds.Tables["Employee"].Rows[0]["EmployeeNumber"].ToString();<br />
				txtFirstName.Text = ds.Tables["Employee"].Rows[0]["FirstName"].ToString();<br />
				txtSurname.Text = ds.Tables["Employee"].Rows[0]["Surname"].ToString();<br />
				txtDateOfBirth.Text = ds.Tables["Employee"].Rows[0]["DateOfBirth"].ToString();<br />
				txtAddress1.Text = ds.Tables["Employee"].Rows[0]["Address1"].ToString();<br />
				txtAddress2.Text = ds.Tables["Employee"].Rows[0]["Address2"].ToString();<br />
				cboDepartment.Text = ds.Tables["Employee"].Rows[0]["DepartmentCode"].ToString();<br />
<br />
				string departmentCode = ds.Tables["Employee"].Rows[0]["DepartmentCode"].ToString();<br />
				DataRow[] departmentRow = ds.Tables["Department"].Select("DepartmentCode = '" + departmentCode + "' ");<br />
				string departmentName = departmentRow[0]["DepartmentName"].ToString();<br />
				<br />
				<br />
				this.UpdateDepartments();//Call to display combo box information<br />
			}	<br />
			catch ( OleDbException ex )<br />
			{<br />
				MessageBox.Show(ex.Message);<br />
			}<br />
			catch ( Exception ex )<br />
			{<br />
				MessageBox.Show(ex.Message);<br />
			}<br />
		}<br />


When l click the update button, l run this code and get an error on the update.

<br />
ds.Tables["Employee"].Rows[0]["FirstName"] = txtFirstName.Text;<br />
ds.Tables["Employee"].Rows[0]["Surname"] = txtSurname.Text;<br />
ds.Tables["Employee"].Rows[0]["DepartmentCode"] = departmentCode;<br />
<br />
da.Update(ds,"Employee"); //Error ocurrs here<br />


I hope someone can help me with this question. very important.

Thanks in advance,

Steve
GeneralMS Money like software Pin
Jassim Rahma24-Jun-05 23:48
Jassim Rahma24-Jun-05 23:48 
GeneralRe: MS Money like software Pin
Colin Angus Mackay25-Jun-05 2:49
Colin Angus Mackay25-Jun-05 2:49 
GeneralRe: MS Money like software Pin
Anonymous26-Jun-05 11:48
Anonymous26-Jun-05 11:48 
GeneralRe: MS Money like software Pin
Colin Angus Mackay26-Jun-05 11:51
Colin Angus Mackay26-Jun-05 11:51 
GeneralRe: MS Money like software Pin
Luis Alonso Ramos25-Jun-05 17:15
Luis Alonso Ramos25-Jun-05 17:15 
Generalpopulating a treeview Pin
deep724-Jun-05 21:33
deep724-Jun-05 21:33 
GeneralRe: populating a treeview Pin
Lars-Inge Tønnessen25-Jun-05 13:02
Lars-Inge Tønnessen25-Jun-05 13:02 
Questionhow sever out-put Music/audio to Clients Pin
Sheharyar_JH24-Jun-05 20:26
Sheharyar_JH24-Jun-05 20:26 
AnswerRe: how sever out-put Music/audio to Clients Pin
mhmo24-Jun-05 21:29
mhmo24-Jun-05 21:29 
QuestionHow to load a Form to a Panel? Pin
pubududilena24-Jun-05 19:17
pubududilena24-Jun-05 19:17 
AnswerRe: How to load a Form to a Panel? Pin
Lars-Inge Tønnessen25-Jun-05 12:51
Lars-Inge Tønnessen25-Jun-05 12:51 
AnswerRe: How to load a Form to a Panel? Pin
SBendBuckeye8-Jul-05 11:00
SBendBuckeye8-Jul-05 11:00 
GeneralHelp - I &#8216;m getting a .NET installation error (urgent) Pin
Member 192995024-Jun-05 13:22
Member 192995024-Jun-05 13:22 
GeneralCustom Event Firing Once per Instance Pin
SBendBuckeye24-Jun-05 10:20
SBendBuckeye24-Jun-05 10:20 
GeneralRe: Custom Event Firing Once per Instance Pin
Adam Goossens24-Jun-05 21:49
Adam Goossens24-Jun-05 21:49 
GeneralRe: Custom Event Firing Once per Instance Pin
SBendBuckeye25-Jun-05 7:35
SBendBuckeye25-Jun-05 7:35 
GeneralRe: Custom Event Firing Once per Instance Pin
Adam Goossens25-Jun-05 19:04
Adam Goossens25-Jun-05 19:04 

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.