SQL 学习(二)INNER JOIN

通过SQL 联表查询:(一看就明白)

 private void Form1_Load(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=myServer;Initial Catalog=Northwind;Integrated Security=True;");//数据连接字符串
            SqlDataAdapter dap = new SqlDataAdapter("SELECT Orders.OrderID, Customers.CompanyName, Orders.OrderDate FROM Orders INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID", con);       //INNER JOIN     
            DataSet ds = new DataSet();
            dap.Fill(ds, "table");
            dataGridView1.DataSource = ds.Tables[0].DefaultView;
        }

 

联接ACCESS数据库进行多表查询:
        private void Form1_Load(object sender, EventArgs e)
        {
                    
           OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=myDataBase.accdb;");
           OleDbDataAdapter dap = new OleDbDataAdapter("SELECT Course.course, Course.classroom, Faculty.faculty_name,Faculty.office,Faculty.email FROM Faculty INNER JOIN Course ON Faculty.faculty_id = Course.faculty_id",conn);
           DataSet ds = new DataSet();
           dap.Fill(ds);
           dataGridView1.DataSource = ds.Tables[0].DefaultView;
        }

SQL 学习(二)INNER JOIN,布布扣,bubuko.com

SQL 学习(二)INNER JOIN

上一篇:Oracle存储过程生成日期维度


下一篇:使用ODBC 数据库 ,运行程序时 出现 “遇到不适当的参数”