Click here to Skip to main content
15,889,931 members
Home / Discussions / Database
   

Database

 
GeneralRe: Insert problem Pin
Luis Alonso Ramos26-Jun-05 5:31
Luis Alonso Ramos26-Jun-05 5:31 
GeneralRe: Insert problem Pin
toxcct26-Jun-05 7:33
toxcct26-Jun-05 7:33 
GeneralRe: Insert problem Pin
Luis Alonso Ramos26-Jun-05 9:12
Luis Alonso Ramos26-Jun-05 9:12 
GeneralRe: Insert problem Pin
Blue_Skye26-Jun-05 20:13
Blue_Skye26-Jun-05 20:13 
GeneralRe: Insert problem Pin
Luis Alonso Ramos27-Jun-05 5:15
Luis Alonso Ramos27-Jun-05 5:15 
GeneralRe: Insert problem Pin
Blue_Skye26-Jun-05 7:40
Blue_Skye26-Jun-05 7:40 
GeneralRe: Insert problem Pin
Luis Alonso Ramos26-Jun-05 9:13
Luis Alonso Ramos26-Jun-05 9:13 
Generalupdating a database Pin
steve_rm25-Jun-05 2:01
steve_rm25-Jun-05 2:01 
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
Generalvariable queries for vb.net Pin
WetRivrRat24-Jun-05 22:37
WetRivrRat24-Jun-05 22:37 
GeneralRe: variable queries for vb.net Pin
Colin Angus Mackay25-Jun-05 2:38
Colin Angus Mackay25-Jun-05 2:38 
GeneralRe: variable queries for vb.net Pin
WetRivrRat27-Jun-05 2:40
WetRivrRat27-Jun-05 2:40 
Generalhello,sqldatabase registering error Pin
Anonymous24-Jun-05 10:53
Anonymous24-Jun-05 10:53 
GeneralRe: hello,sqldatabase registering error Pin
NeverHeardOfMe24-Jun-05 12:25
NeverHeardOfMe24-Jun-05 12:25 
GeneralRe: hello,sqldatabase registering error Pin
Anonymous24-Jun-05 21:33
Anonymous24-Jun-05 21:33 
Questionbind parameter in a datagrid's column ? Pin
newprog24-Jun-05 2:30
newprog24-Jun-05 2:30 
GeneralSQL Datetime - Independent Format Pin
Seraphin24-Jun-05 0:38
Seraphin24-Jun-05 0:38 
GeneralRe: SQL Datetime - Independent Format Pin
Colin Angus Mackay24-Jun-05 3:42
Colin Angus Mackay24-Jun-05 3:42 
GeneralRe: SQL Datetime - Independent Format Pin
Seraphin25-Jun-05 3:44
Seraphin25-Jun-05 3:44 
GeneralDateTime datatype Pin
Blue_Skye23-Jun-05 18:09
Blue_Skye23-Jun-05 18:09 
GeneralRe: DateTime datatype Pin
Colin Angus Mackay23-Jun-05 21:06
Colin Angus Mackay23-Jun-05 21:06 
GeneralRe: DateTime datatype Pin
Yulianto.23-Jun-05 21:29
Yulianto.23-Jun-05 21:29 
GeneralRe: DateTime datatype Pin
Colin Angus Mackay23-Jun-05 23:07
Colin Angus Mackay23-Jun-05 23:07 
GeneralRe: DateTime datatype Pin
Yulianto.24-Jun-05 16:18
Yulianto.24-Jun-05 16:18 
GeneralRe: DateTime datatype Pin
Blue_Skye24-Jun-05 18:59
Blue_Skye24-Jun-05 18:59 
GeneralRe: DateTime datatype Pin
Colin Angus Mackay24-Jun-05 21:31
Colin Angus Mackay24-Jun-05 21:31 

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.