zoukankan      html  css  js  c++  java
  • C#连接db2数据库

    1、通过OLE DB for DB2驱动

        string strSql = @"select phone_no from no_store where id<5";
        string strConn = "Provider=IBMDADB2;Data Source=数据库名;UID=用户名;PWD=密码;";
        using (OleDbConnection conn = new OleDbConnection(strConn))
        {
            OleDbCommand cmd = new OleDbCommand(strSql, conn);
            try
            {
                conn.Open();
                OleDbDataAdapter adp = new OleDbDataAdapter(cmd);
                DataSet ds = new DataSet();
                adp.Fill(ds);
                DataTable dt = ds.Tables[0];
    
                if (dt != null)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        Console.WriteLine("电话" + i + ":" + dt.Rows[i][0].ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        Console.Read();

    2、通过IBM提供的IBM.data.DB2.DLL

        string strSql = @"select phone_no from no_store where id<5";
        string strConn = "Database=数据库名;UID=用户名;PWD=密码;";
        using (DB2Connection conn = new DB2Connection(strConn))
        {
            DB2Command cmd = new DB2Command(strSql, conn);
            try
            {
                conn.Open();
                DB2DataAdapter adp = new DB2DataAdapter(cmd);
                DataSet ds = new DataSet();
                adp.Fill(ds);
                DataTable dt = ds.Tables[0];
    
                if (dt != null)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        Console.WriteLine("电话" + i + ":" + dt.Rows[i][0].ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        Console.Read();
  • 相关阅读:
    POJ3352 Road Construction (双连通分量)
    强连通分量(模板)
    图基本概念
    Air Raid(最小路径覆盖)
    Machine Schedule(最小覆盖)
    hdoj 1564 Play a game
    nyoj 483 Nightmare【bfs+优先队列】
    hdoj 1083 Courses【匈牙利算法】
    hdoj 2036 改革春风吹满地
    nyoj 353 3D dungeon
  • 原文地址:https://www.cnblogs.com/xubao/p/10984069.html
Copyright © 2011-2022 走看看