分享

VS2005连接Mysql,SQL Server, Access,Oracle

 花非花。 2010-09-16
  VS2005连接Mysql,SQL Server, Access,Oracle 收藏
1 VS2005连接MySql
下载MySql.Data.dll ,之后添加引用到项目中
  添加:   using MySql.Data.MySqlClient;
         DataSet ds = new DataSet();
        string sql = "select * from student";
        string constr="server=localhost;User Id=root;password=zhihua1124;Database=mysqldb;";
        MySqlConnection con = new MySqlConnection(constr);
        con.Open();
        try
        {
            MySqlDataAdapter adapter = new MySqlDataAdapter();
            adapter.SelectCommand = new MySqlCommand(sql, con);
            adapter.Fill(ds);
            con.Close();
        }
        catch (Exception ex)
        {
        }
2 VS2005连接SQL Server 2005
        string constr="data source=localhost\\sqlexpress;Initial Catalog=sqlserverdb;Integrated Security=True";
        string sql="select * from student";
        SqlConnection con = new SqlConnection(this.getConnString());
        DataSet ds = new DataSet();
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand(sql, con);
        adapter.Fill(ds);
3 VS2005连接Access
       try
        {
            string constr= "provider=microsoft.jet.oledb.4.0;"+@"Data Source=D:\Microsoft Visual Studio 8\Projects\DDBI22\App_Data\accessdb.mdb";
            string sql="select * from student";
            OleDbConnection con = new OleDbConnection(constr);
            con.Open();
            OleDbCommand sc = new OleDbCommand(sql, con);
            sc.ExecuteNonQuery();
        }
        catch (SqlException e)
        {
            Console.Write(e.StackTrace);
        }
4 VS2005连接Oracle
  
   添加引用:using System.Data.OracleClient;
  
        try
        {
            string constr="Data Source=oracledb;user=ddbi;password=ddbi;";
            string sql="select * from student";
            OracleConnection con = new OracleConnection(constr);
            con.Open();
            OracleCommand oc = new OracleCommand(sql, con);
            oc.ExecuteNonQuery();
        }
        catch (OracleException e)
        {
            Console.Write(e.StackTrace);
        }
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhihua1124/archive/2008/11/17/3309927.aspx

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章