Ejemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // If it's really the first time we are loading the
        // page,
        if (!Page.IsPostBack)
        {
            // If the session variable is empty, initialize an
            // empty list as the datasource
            if (Session[TableKey] == null)
            {
                Session[TableKey] = new List <TableObject>();
            }
            BindList();

            String database           = "palette_lms";
            String myConnectionString = "server=127.0.0.1;" + "uid=root;" + "pwd=;";
            m_cnx = new MySqlConnection(myConnectionString);
            try
            {
                m_cnx.Open();
                m_cnx.ChangeDatabase(database);
            }
            catch (MySqlException ex)
            {
                Response.Write("Connection to database <" + database + ">" + " could not be established.\r\n");
                Response.Write("Developer insight: " + ex.Message + "\r\n");
            }
            finally
            {
                if (m_cnx != null)
                {
                    if (m_cnx.State == System.Data.ConnectionState.Open)
                    {
                        Session[ConnexionKey] = m_cnx;
                        DB_Name.Text          = database;
                        Response.Write("Connection Established with database " + database + "\r\n");
                        DataTable allTablesSchemaTable = m_cnx.GetSchema("Tables");
                        //DataTable schema = connection.GetSchema("Tables");
                        List <TableObject> TableNames = (List <TableObject>)Session[TableKey];
                        foreach (DataRow row in allTablesSchemaTable.Rows)
                        {
                            // For the array,
                            // - 0 -member represents Catalog;
                            // - 1 -member represents Schema;
                            // - 2 -member represents Table Name;
                            // - 3 -member represents Table Type.
                            // Now we specify the Table Name of the table what we want to get schema information.
                            String currentTableName = row[2].ToString();
                            TableNames.Add(new TableObject(currentTableName));
                        }
                        Available_Tables.DataSource = TableNames;
                        Available_Tables.DataBind();
                    }
                }
            }
        }
        return;
    }
Ejemplo n.º 2
0
 private void BindList()
 {
     Available_Tables.DataSource = (List <TableObject>)Session[TableKey];
     Available_Tables.DataBind();
 }