There is a database with the following structure (simplified):
My program displays one of these tables with the ability to edit the content (I use WinForm). Nearby is a button that sends the modified table back to the database.
The problem is that if you use the generated commands (OleDbCommandBuilder), then when sending data to the database I get an error indicating the columns from other tables.
For example. If I change something in the "disease" table: In the DataTable "Table" there is no DataColumn "Patient number" for this SourceColumn "Patient number".
If I change something in the "visits" table: INSERT INTO syntax error. Or the same with UPDATE or DELETE commands.
Obviously, you need to make commands manually. But from the examples on MSDN it is not clear how to describe the relationships between the tables. Articles themselves:
https://msdn.microsoft.com/ru-ru/library/system.data.oledb.oledbdataadapter.insertcommand(v=vs.110).aspx https://msdn.microsoft.com/ru-ru/library/ system.data.oledb.oledbdataadapter.updatecommand (v = vs.110) .aspx https://msdn.microsoft.com/ru-ru/library/system.data.oledb.oledbdataadapter.deletecommand(v=vs.110) .aspx
Actually, help make the right commands for the tables "disease" and "visit". Or at least explain the principle.
Even better, if you know a simpler way.
If it is important, the preparation of the form:
protected string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb"; protected OleDbConnection connection = new OleDbConnection(); protected OleDbDataAdapter adapter; protected OleDbCommandBuilder cBuilder; DataSet dataSet; public Form1() { InitializeComponent(); connection.ConnectionString = conStr; adapter = new OleDbDataAdapter("SELECT * FROM TABLE_NAME", connection); dataSet = new DataSet(); cBuilder = new OleDbCommandBuilder(adapter); adapter.Fill(dataSet); connection.Open(); adapter.UpdateCommand = cBuilder.GetUpdateCommand(true); adapter.InsertCommand = cBuilder.GetInsertCommand(true); connection.Close(); }
I save the data from the table to the database:
private void saveButton_Click(object sender, EventArgs e) { adapter.Update(dataSet); }
The boot method seems to be irrelevant.
It was a mistake to use MS Access. Since, in this situation, I cannot select another database, I will have to use another solution.