CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Threaded View

  1. #1
    Join Date
    Jan 2011
    Posts
    59

    LINQ Query to retrieve Data from multiple Database tables

    Hey there yet again.

    I´m still crushing my teeth at using LINQ in C# correctly..
    right now i´m trying to create a view or temporary table to retrieve the data from my 3 tables where The ID == REF_ID.
    i know i got to use the JOIN in some way, but don´t really get yet, how to do that.
    I got 3 tables
    Rezepttabelle (parent table with RezeptID column)
    Kategorien (child table with REF_RezeptID column)
    Zutaten (child table with REF_RezeptID column)

    I want to get all the data joined where REF_RezeptID = RezeptID and display that data in a datagridview on my form1.

    Code:
            /// <summary>
            /// 
            /// </summary>
            public void Rezept_load()
            {
                //a new connection to the database is created.
                SqlConnection con = new SqlConnection();
                //connection string to the database
                con.ConnectionString =
                         @"Data Source=vm-msdb01\fme;Initial Catalog=Lisa;Persist Security Info=True;User ID=sa;Password=fmefme";
                //connection opened
                con.Open();
    
                //the values from the various textboxes are added to the main table.
                //the id is created automatically.
                SqlCommand cmd = new SqlCommand("");
                
                try
                {
                    cmd.ExecuteNonQuery();
                }
    
                //any errors occuring are caught here
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
    
                //the connection is closed
                finally
                {
                    con.Close();
                }
            }
    that&#180;s my code so far, as u can see, the sql query is empty, for i have no idea how to make my statement...
    maybe you can help me, i really hope so

    Greetings and Cheers

    Cheers
    Last edited by LisaWvL; July 4th, 2011 at 05:04 AM. Reason: Please ignore the // comments, they´re not up to date!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured