this is my csharp code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace MutlitableDatasetApp
{
public partial class MainForm : Form
{
//form wide dataset.
private DataSet autoLotDS = new DataSet("AutoLot");
//Make use of command builders to simplify data adapter configuration.
private SqlCommandBuilder sqlCBInventory;
private SqlCommandBuilder sqlCBCustomers;
private SqlCommandBuilder sqlCBOrders;
//our data adapters (for each table).
private SqlDataAdapter invTableAdapter;
private SqlDataAdapter custTableAdapter;
private SqlDataAdapter ordersTableAdapter;
//form wide connection string.
private string cnStr = string.Empty;
public MainForm()
{
InitializeComponent();
//get connection string from *.config file.
cnStr = ConfigurationManager.ConnectionStrings["AutoLotSqlProvider"].ConnectionString;
//create adapters.
invTableAdapter = new SqlDataAdapter("Select * from Inventory", cnStr);
custTableAdapter = new SqlDataAdapter("Select * from Customers", cnStr);
ordersTableAdapter = new SqlDataAdapter("Select * from Orders", cnStr);
//autogenerate commands.
sqlCBInventory = new SqlCommandBuilder(invTableAdapter);
sqlCBCustomers = new SqlCommandBuilder(custTableAdapter);
sqlCBOrders = new SqlCommandBuilder(ordersTableAdapter);
//fill tables in DS
invTableAdapter.Fill(autoLotDS, "Inventory");
custTableAdapter.Fill(autoLotDS, "Customers");
ordersTableAdapter.Fill(autoLotDS, "Orders");
//build relations between tables.
BuildTableRelationship();
//bind to grids
dataGridViewInventory.DataSource = autoLotDS.Tables["Inventory"];
dataGridViewCustomers.DataSource = autoLotDS.Tables["Customers"];
dataGridViewOrders.DataSource = autoLotDS.Tables["Orders"];
}
private void BuildTableRelationship()
{
// create customerorder data relation object.
DataRelation dr = new DataRelation("CustomerOrder", autoLotDS.Tables["Customers"].Columns["CustID"],
autoLotDS.Tables["Orders"].Columns["CustID"]);
autoLotDS.Relations.Add(dr);
//create inventoryorder data relation object.
dr = new DataRelation("InventoryOrder", autoLotDS.Tables["Inventory"].Columns["CarID"],
autoLotDS.Tables["Orders"].Columns["CarID"]);
autoLotDS.Relations.Add(dr);
}
private void btnUpdateDatabase_Click(object sender, EventArgs e)
{
try
{
invTableAdapter.Update(autoLotDS, "Inventory");
custTableAdapter.Update(autoLotDS, "Customers");
ordersTableAdapter.Update(autoLotDS, "Orders");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
i have 3 tables my problem is when i update the col CarID in Inventory table it should update the Orders CarID col too but it gives me an error
as you can see on the image please help me i really want to learn this language its really cool and fun