Exemple #1
0
        public List <sys_dic> getsysdic(string tablename)
        {
            string sql = "select * from sys_dic where table_name = '" + tablename + "'";

            MySqlParameter[]    parms = null;
            Helpers.MySqlHelper a     = new Helpers.MySqlHelper();
            DataTable           dt    = a.ExecuteDataTable(sql, parms);
            List <sys_dic>      list  = new List <sys_dic>();

            list = DataTableExtend.ToDataList <sys_dic>(dt);
            return(list);
        }
        private void RefreshMysql(String uid, String pwd)
        {
            string mysqlConnStr = "server=" + url.Text + ";user id=" + uid + ";password="******";database=information_schema";  //根据自己的设置

            Helpers.MySqlHelper mysqlHelper = new Helpers.MySqlHelper(mysqlConnStr);

            String sql = "select schema_name name from SCHEMATA ";

            MySqlParameter[] parms = new MySqlParameter[] { };
            DataTable        dt    = mysqlHelper.ExecuteDataTable(sql, parms);

            comboBox1.DataSource    = dt;
            comboBox1.DisplayMember = "name";
            comboBox1.ValueMember   = "name";
        }
        private void button2_Click(object sender, EventArgs e)
        {
            String uid = username.Text;
            String pwd = password.Text;

            //刷新数据库连接
            if (this.validDbUser(uid, pwd))
            {
                if (rb_sqlserver.Checked) //连接sqlServer
                {
                    String db          = comboBox1.Text;
                    bool   isConnected = this.connectSqlServerDb(db, uid, pwd);

                    if (isConnected)
                    {
                        conn_info.Clear();
                        System.IO.StringWriter   sw = new System.IO.StringWriter();
                        System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(sw);
                        //当前数据库所有的用户表
                        DataTable dt = SqlServerHelper.getTableOfCurrentDatabase();
                        dt.WriteXml(xw);
                        string s = sw.ToString();
                        conn_info.Text = "连接成功……\n所有的用户表展示如下:\n" + s;
                    }
                    else
                    {
                        conn_info.Text = "连接失败……";
                    }
                }
                else if (rb_mysql.Checked) //连接mysql
                {
                    String db          = comboBox1.Text;
                    bool   isConnected = this.connectMySql(db, uid, pwd);
                    if (isConnected)
                    {
                        string mysqlConnStr             = "server=" + url.Text + ";user id=" + uid + ";password="******";database=" + db; //根据自己的设置
                        Helpers.MySqlHelper mysqlHelper = new Helpers.MySqlHelper(mysqlConnStr);

                        String           sql   = "show tables ";
                        MySqlParameter[] parms = new MySqlParameter[] { };
                        DataTable        dt    = mysqlHelper.ExecuteDataTable(sql, parms);

                        conn_info.Clear();
                        System.IO.StringWriter   sw = new System.IO.StringWriter();
                        System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(sw);
                        //当前数据库所有的用户表
                        dt.WriteXml(xw);
                        string s = sw.ToString();
                        conn_info.Text = "连接成功……\n" + s;
                    }
                    else
                    {
                        conn_info.Text = "连接失败……";
                    }
                }
                else if (rb_oracle.Checked)
                {
                    this.RefreshOracle(uid, pwd);
                }
            }
        }