Use multiple tables linq query in the dataset

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;

namespace QueryTablesByLinq
{
    public partial class Frm_Main : Form
    {
        public Frm_Main()
        {
            InitializeComponent();
        }

        void Frm_Main_Load Private (SENDER Object, EventArgs E)
        {
            String the ConnectionString = "Server-GI7E47AND9R WIN = \ the LS; Database = db_TomeTwo; UID = SA; pwd ="; // declare the connection string
            using (SqlConnection Conn = new SqlConnection ( ConnectionString )) // create a database connection object
            {
                String sqlstr = "SELECT from tb_Register"; // definition of query
                SqlDataAdapter da = new SqlDataAdapter (sqlstr, Conn); // Create a data object bridge
                DataSet ds = new DataSet (); / / create data objects
                da.Fill (ds, "register") ; // fill first data table data to the DataSet
                sqlstr = "the SELECT
from tb_Sale"; // define the query
                da.SelectCommand.CommandText = sqlstr; // specified The second query
                da.Fill (ds, "sale") ; // fill the second data table data to the DataSet
                // query pharmaceutical sales record information
                var = Result from R & lt ds.Tables in [ "Register"] AsEnumerable ().
                             the Join ds.Tables in S [ "Sale"]. AsEnumerable ()
                             ON r.Field <String> ( "No Drug") equals s.Field <string> ( " No Drug")
                             SELECT new new
                             {
                                 drug_name R & lt = [ "Drug name "] .ToString (),
                                 drug_factory R & lt = [" manufacturer "] .ToString (),
                                 drug_sale S = [" sales "] .ToString ()
                             };
                foreach (var item in result) // traverse the output results
                {
                    RichTextBox1.Text + = "Drug Name:" + item.drug_name + " ** manufacturer:" + item.drug_factory + " ** Sales:" + item.drug_sale + "\ n-";
                }
            }
        }
    }
}

Guess you like

Origin blog.51cto.com/14510327/2434388