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();

 

相关文章:

  • 2021-05-27
  • 2021-12-05
  • 2021-11-29
  • 2021-09-23
  • 2021-10-03
猜你喜欢
  • 2022-12-23
  • 2022-01-19
  • 2022-12-23
  • 2021-09-02
  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
相关资源
相似解决方案