Exemplo n.º 1
0
        private void initDataSet()
        {
            string path = System.Environment.CurrentDirectory + "\\All.mdb";
            bool   flag = AccessDbHelper.CreateAccessDb(path);

            if (flag)
            {
                Console.WriteLine("create success");
            }
            else
            {
                Console.WriteLine("already exits");
            }

            MyDataSet             = new Access();
            TabPage.SelectedIndex = 1;
        }
Exemplo n.º 2
0
        private void CreatetableButton_Click(object sender, EventArgs e)
        {
            String mytablename = TableName.Text.Trim();
            String columnames  = Colums.Text.Trim();

            if (string.IsNullOrWhiteSpace(mytablename))
            {
                tablenametips.Text      = "表名不能为空";
                tablenametips.ForeColor = Color.Red;
                return;
            }

            if (MyDataSet.GetTableNameList().Contains(mytablename))
            {
                tablenametips.Text      = "表名已存在,请更换";
                tablenametips.ForeColor = Color.Red;
                return;
            }

            if (string.IsNullOrWhiteSpace(columnames))
            {
                tablenametips.Text      = "字段名不能为空";
                tablenametips.ForeColor = Color.Red;
                return;
            }

            freshCreateTable();

            string[] mycolums = columnames.Split(',');

            string s = "表名为:" + mytablename + "\r\n包含字段有: ";

            for (int i = 0; i < mycolums.Length; i++)
            {
                s += (i + 1) + " : " + mycolums[i] + ",    ";
            }
            s += "是否确认建表?";
            DialogResult result = MessageBox.Show(s, "确认健表", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (result == DialogResult.OK)
            {
                ADOX.Column[] columns = new ADOX.Column[mycolums.Length + 2];
                columns[0] = new ADOX.Column()
                {
                    Name = "id", Type = DataTypeEnum.adInteger, DefinedSize = 9
                };

                for (int i = 0; i < mycolums.Length; i++)
                {
                    columns[i + 1] = new ADOX.Column()
                    {
                        Name = mycolums[i], Type = DataTypeEnum.adLongVarWChar, DefinedSize = 500
                    };
                }
                columns[mycolums.Length + 1] = new ADOX.Column()
                {
                    Name = "importfilename", Type = DataTypeEnum.adLongVarWChar, DefinedSize = 500
                };
                bool flag = AccessDbHelper.CreateAccessTable(System.Environment.CurrentDirectory + "\\All.mdb", mytablename, columns);
                if (flag)
                {
                    MessageBox.Show("建表成功");
                    CreatemMatchFile(mytablename);
                    freshTableList();
                    freshTableTree();
                }
                else
                {
                    MessageBox.Show("建表失败");
                }
            }
        }