using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form5 : Form
    {
        public Form5()
        {
            InitializeComponent();
        }

        private void Form5_Load(object sender, EventArgs e)
        {
            //建立SQL Server数据库连接
            string connstring = "Data Source=(local);Initial Catalog=school;User ID=sa";
            SqlConnection connection = new SqlConnection(connstring);
            connection.Open();
            string sqlstring = "select * from student";
            SqlCommand mycom = new SqlCommand(sqlstring, connection);
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = mycom;
            //设置DataSet对象
            DataSet SQLds = new DataSet();
            adapter.Fill(SQLds);
            //释放数据库连接资源
            connection.Dispose();
            connection.Close();
            connection = null;


            //建立Access数据库连接
            string AccessConStr = @"provider=microsoft.Jet.OleDb.4.0;data source=c:\\school.mdb;";
            OleDbConnection Accessconn = new OleDbConnection(AccessConStr);
            Accessconn.Open();
            string Accesssql = "select * from student";
            OleDbCommand Accesscomm = new OleDbCommand(Accesssql, Accessconn);
            OleDbDataAdapter Accessadap = new OleDbDataAdapter();
            Accessadap.SelectCommand = Accesscomm;
            //设置DataSet对象
            DataSet Accessds = new DataSet();
            Accessadap.Fill(Accessds);
            //释放数据库连接资源
            Accessconn.Dispose();
            Accessconn.Close();
            Accessconn = null;

            SQLds.Merge(Accessds);
            SQLds.AcceptChanges();

            for (int i = 0; i < SQLds.Tables[0].Rows.Count; i++)
            {
                //label1.Text += ds.Tables[0].Rows[i]["sname"].ToString()+"\n";
                label1.Text += SQLds.Tables[0].Rows[i][1].ToString() + "\n";
            }
       
        }
    }
}