Thursday, 21.11.2024, 09:30
Useful scripts of Oracle
Main Registration Login
Welcome, Guest · RSS
Search
Site menu
Oracle
Monitoring
PL/SQL
Oracle & Other Programs
Login form
 Populate DataTable
using System;
using System;
using System.IO;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
namespace FunctionsTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
      private void Form1_Load(object sender, EventArgs e)
        {
 
        }
       public static void PopulateDataTables()
        {
            // Connect to database orcl , user HR, pasword hr
            OracleConnection conn = new OracleConnection();
            conn.ConnectionString = "Data Source=" + "orcl" +
                                    ";Persist Security Info=true;User ID=" + "hr" +
                                    ";Password=" + "hr" + ";";
            conn.Open();

           // create dataset
            DataSet dts = new DataSet();

            /* fill data adapter with "dba_users" (1st query result) "dba_tablespaces"(2nd query result)
             * "inv_obj"((2nd query result)*/
            try
            {
                String queryString = " select username, user_id, password,account_status, lock_date," +
                                 " expiry_date,default_tablespace,temporary_tablespace, " +
                                 " created, profile, initial_rsrc_consumer_group,external_name, " +
                                 " instr(account_status,'LOCKED') sts,instr(account_status,'EXPIRED') exped " +
                                 " from sys.dba_users order by USERNAME";
                OracleCommand command = new OracleCommand(queryString, conn);
                OracleDataAdapter da = new OracleDataAdapter(command);
                if (!dts.Tables.Contains("dba_users"))
                    dts.Tables.Add("dba_users");
                da.Fill(dts, "dba_users");
                queryString = "select * from dba_tablespaces";
                command = new OracleCommand(queryString, conn);
                da = new OracleDataAdapter(command);
                if (!dts.Tables.Contains("dba_tablespaces"))
                    dts.Tables.Add("dba_tablespaces");
                da.Fill(dts, "dba_tablespaces");
                queryString = " SELECT o.OWNER, o.OBJECT_NAME, o.OBJECT_TYPE " +
                              " FROM DBA_OBJECTS o " +
                               " WHERE  o.STATUS='INVALID'";
                command = new OracleCommand(queryString, conn);
                da = new OracleDataAdapter(command);
                if (!dts.Tables.Contains("inv_obj"))
                    dts.Tables.Add("inv_obj");
                da.Fill(dts, "inv_obj");
             }
            catch (OracleException oex)
            {
              throw new Exception(oex.Message);
            }
        }
   }
}
Copyright MyCorp © 2024
Statistics

Total online: 1
Guests: 1
Users: 0
Site friends
  • Oracle UHB-rus
  • Oracle UHB-arm
  • Online jobs