none
Dataset mit 3 Tabellen, ComboBox befüllen RRS feed

  • Frage

  • Hallo,

    http://www1.minpic.de/bild_anzeigen.php?id=140841&key=73559177&ende

    http://www1.minpic.de/bild_anzeigen.php?id=140844&key=10672182&ende

    http://www1.minpic.de/bild_anzeigen.php?id=140845&key=15665863&ende

    ich habe ja die 3 Tabellen

    Type - Name
    1:n Global - Name
    1:n Dynamic - Name


    Ziel:
    Eine Combobox befüllen, mit allen möglichen Namen.

      Anhanad einer ID, kann ich dann herausfiltern, wo der Name herkommt.

    Wie erreiche ich das?
    Ggf. mit LinQ, oder?

    Das habe ich nicht.

      // Create a database connection string

    Ich habe nur ein Dataset!!

            String str = String.Format("user id=sa;password=;initial catalog=Northwind;data source=(local)");

     

    public void InitDataset()
      {
       try
       {
        // Create a database connection string
        String str = String.Format("user id=sa;password=;initial catalog=Northwind;data source=(local)");
    
        // Create the database connection object
        SqlConnection sqlcon = new SqlConnection (str);
        sqlcon.Open (); // open it
    
        // Create the export query strings
        String strCustomers = String.Format ("SELECT * FROM Customers WHERE City='London'");
    
        String strOrders = String.Format ("SELECT O.* FROM Orders O INNER JOIN Customers C ON O.CustomerID = C.CustomerID WHERE C.City='London' ");
    
        SqlCommand sqlCustomers = new SqlCommand (strCustomers, sqlcon);
        SqlCommand sqlOrders = new SqlCommand (strOrders, sqlcon);
    
        SqlDataAdapter ProjectAdapter = new SqlDataAdapter (sqlCustomers);
        SqlDataAdapter OrdersAdapter = new SqlDataAdapter (sqlOrders);
    
        DataTable CustomersTable = MyDataSet.Tables.Add ("Customers");
        DataTable OrdersTable = MyDataSet.Tables.Add ("Orders");
    
        ProjectAdapter.Fill (CustomersTable);
        OrdersAdapter.Fill (OrdersTable);
    
        MyDataSet.Relations.Add (CustomersTable.Columns[0],
                     OrdersTable.Columns[1]);
       }
       catch (Exception e)
       {
        MessageBox.Show (this, e.Message);
       }
    
      } 
    Danke + Grüße Andreas
    Montag, 14. März 2011 14:08

Alle Antworten

  • Hallo,

    ok, falls nicht geht, vielleicht hat jemand eine Idee.

    1 Tabelle

    http://www1.minpic.de/bild_anzeigen.php?id=141015&key=75020537&ende

      Dataset - BindingsSource - dann wähle ich Namen, wie kommt man dann am einfachsten auf die restl. Variablen?

    • Comment
      - Index
     private void cbVariable01_SelectedIndexChanged(object sender, EventArgs e)
        {
          string s1 = cbVariable01.Text;
          txtCodeContent01.Text = Machine.GetMarkingContent(7, 1, "D1", 0);
    
          dsVariableNames myVariableNames = cbVariable01.DataSource as dsVariableNames;
          dsVariableNames myVariableNames2 = cbVariable01.DataSource as dsVariableNames;
    
           dsVariableNames myVariableNames3 = bS1.Current as dsVariableNames;
           int zz = bS1.CurrencyManager.Count;
    
           DataRowView row = (DataRowView)bS1.Current;
           string comment = row["Comment"].ToString();
    
    Grüße Andreas
    Dienstag, 15. März 2011 20:14