wwjd_kilden
Member
Hi.
I'm not sure if my problem lies in this bit of code or somewhere else, but the exception is thrown from my dataadapter when call the update command on the first dataadapter. .
Error message says Additional information: Missing the DataColumn 'company_ID' in the DataTable 'machine' for the SourceColumn 'company_ID
I have two tables (machine and ownership), and I want to update them both. However, it seems that my dataadapter wants to add the first column of one table (ownership) to the other table (machine), even though I have two separate data adapters.
Knowing myself, it is probably some tiny, silly error
(It saved to the database without problems before I tried adding the code to save to the ownership table)
Ideas? Am I missing something obvious? (I'm very good at that....) I can post more of my code if needed.
mysql> explain machine;
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| SN | varchar(10) | NO | PRI | NULL | |
| model | varchar(4) | YES | | NULL | |
| machinetype | varchar(30) | YES | | NULL | |
+-------------+-------------+------+-----+---------+-------+
mysql> explain ownership;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| company_ID | int(3) | NO | PRI | NULL | |
| machine_SN | varchar(10) | NO | PRI | NULL | |
| contract | varchar(4) | YES | | NULL | |
| contact | int(3) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
C#
if (tablename == "machine")
{
foreach (DataColumn c in ds.Tables[tablename].Columns)
{
// Add values from list into the datarow in corresponding columns
string colname = c.ColumnName;
row[colname] = fieldList;
i++;
}
//-----------------------------------------------------
ds2 = new DataSet("ownership");
string q = @"SELECT * from ownership;";
MySqlCommand cmd2 = new MySqlCommand(q, connection);
da2 = new MySqlDataAdapter(cmd2);
da2.Fill(ds2, "ownership");
ownershiprow = ds2.Tables["ownership"].NewRow(); ;
foreach (DataColumn col in ds2.Tables["ownership"].Columns)
{
// Add values from list into the datarow in corresponding columns
string colname = col.ColumnName;
if (colname == "company_ID" || colname == "contact") { ownershiprow[colname] = Convert.ToInt32(fieldList); } //TEST fordi company_ID og contact er int... endre i DB?
else { ownershiprow[colname] = fieldList; }
i++;
}
// some code inbetween
if (tablename == "machine")
{
ds.Tables[tablename].Rows.Add(row);
MySqlCommandBuilder builder = new MySqlCommandBuilder(da);
da.Update(ds, "machine");
Error msg from dataadapter line: Additional information: Missing the DataColumn 'company_ID' in the DataTable 'machine' for the SourceColumn 'company_ID
controller.showMessage("Data saved to mc");
// ---------------------------------------------------
ds2.Tables["ownership"].Rows.Add(ownershiprow);
MySqlCommandBuilder build = new MySqlCommandBuilder(da2);
da2.Update(ds2, "ownership");
controller.showMessage("Data saved to ownership");
}
I'm not sure if my problem lies in this bit of code or somewhere else, but the exception is thrown from my dataadapter when call the update command on the first dataadapter. .
Error message says Additional information: Missing the DataColumn 'company_ID' in the DataTable 'machine' for the SourceColumn 'company_ID
I have two tables (machine and ownership), and I want to update them both. However, it seems that my dataadapter wants to add the first column of one table (ownership) to the other table (machine), even though I have two separate data adapters.
Knowing myself, it is probably some tiny, silly error
(It saved to the database without problems before I tried adding the code to save to the ownership table)
Ideas? Am I missing something obvious? (I'm very good at that....) I can post more of my code if needed.
mysql> explain machine;
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| SN | varchar(10) | NO | PRI | NULL | |
| model | varchar(4) | YES | | NULL | |
| machinetype | varchar(30) | YES | | NULL | |
+-------------+-------------+------+-----+---------+-------+
mysql> explain ownership;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| company_ID | int(3) | NO | PRI | NULL | |
| machine_SN | varchar(10) | NO | PRI | NULL | |
| contract | varchar(4) | YES | | NULL | |
| contact | int(3) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
C#
if (tablename == "machine")
{
foreach (DataColumn c in ds.Tables[tablename].Columns)
{
// Add values from list into the datarow in corresponding columns
string colname = c.ColumnName;
row[colname] = fieldList;
i++;
}
//-----------------------------------------------------
ds2 = new DataSet("ownership");
string q = @"SELECT * from ownership;";
MySqlCommand cmd2 = new MySqlCommand(q, connection);
da2 = new MySqlDataAdapter(cmd2);
da2.Fill(ds2, "ownership");
ownershiprow = ds2.Tables["ownership"].NewRow(); ;
foreach (DataColumn col in ds2.Tables["ownership"].Columns)
{
// Add values from list into the datarow in corresponding columns
string colname = col.ColumnName;
if (colname == "company_ID" || colname == "contact") { ownershiprow[colname] = Convert.ToInt32(fieldList); } //TEST fordi company_ID og contact er int... endre i DB?
else { ownershiprow[colname] = fieldList; }
i++;
}
// some code inbetween
if (tablename == "machine")
{
ds.Tables[tablename].Rows.Add(row);
MySqlCommandBuilder builder = new MySqlCommandBuilder(da);
da.Update(ds, "machine");
Error msg from dataadapter line: Additional information: Missing the DataColumn 'company_ID' in the DataTable 'machine' for the SourceColumn 'company_ID
controller.showMessage("Data saved to mc");
// ---------------------------------------------------
ds2.Tables["ownership"].Rows.Add(ownershiprow);
MySqlCommandBuilder build = new MySqlCommandBuilder(da2);
da2.Update(ds2, "ownership");
controller.showMessage("Data saved to ownership");
}