Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Edit a datatable from datagridview with a realtion to an other table

$
0
0

Hi,

I have two tables Table FAMILIE which stores the ID from table ORDE.
When i open Table FAMILIE with a dataadapter and show in in a datagridview i would like to be able to choose an ID from the ORDE table and save it to Table FAMILIE.

Table FAMILIE
ID             NUMBER
NAME         VARCHAR2(50)
ORDE_ID        NUMBER

Table ORDE
ID            NUMBER
NAME    VARCHAR2

I have this so far:

private void SelectFromTableFAMILIE(string TableName)
   {
       string SelectSql = "select * from " + TableName;

       // Create a new data adapter based on the specified query.
       da = new SQLiteDataAdapter(SelectSql, dbConnection);

       // Create a command builder to generate SQL update, insert, and
       // delete commands based on selectCommand.
       SQLiteCommandBuilder commandBuilder = new SQLiteCommandBuilder(da);

       // Populate a new data table and bind it to the BindingSource.
       dt = new DataTable
       {
           Locale = CultureInfo.InvariantCulture
       };
       da.Fill(dt);

       var OrdeAdapter = new SQLiteDataAdapter("SELECT * FROM ORDE", dbConnection);
       var OrdeTable = new DataTable();
       OrdeAdapter.Fill(OrdeTable);

		//create a combobox in the datagridview
       var ordeComboBoxColumn = new DataGridViewComboBoxColumn();
       ordeComboBoxColumn.Name = "ordeComboBoxColumn";
       ordeComboBoxColumn.HeaderText = "ORDE_ID";

       ordeComboBoxColumn.DataSource = OrdeTable;
       ordeComboBoxColumn.DataPropertyName = "ID";
       ordeComboBoxColumn.DisplayMember = "NAAM";
       ordeComboBoxColumn.DisplayMember = "ID";
       this.DataGridView1.Columns.Add(ordeComboBoxColumn);

       bindingSource1.DataSource = dt;

       DataGridView1.DataSource = bindingSource1;

       DataGridView1.AutoResizeColumns(
               DataGridViewAutoSizeColumnsMode.AllCells);

   }

First problem: in my datagridview i now have 2 columns ORDE_ID. (See picture)
Second problem. I can choose an ORDE_ID in the added combobox but i can not save it with the dataadapter da.

ORDE_ID twice in the datagridview


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>