示例#1
0
        private void Column_Click(object sender, EventArgs e)
        {
            ColName      dlg = new ColName("Input Column Name");
            DialogResult ret = dlg.ShowDialog();

            if (ret == DialogResult.OK)
            {
                column = dlg.colName;

                dataGrid.Columns.Add(column, column);
            }
        }
示例#2
0
        private void mnuSaveas_Click(object sender, EventArgs e)
        {
            ColName      dlg = new ColName("Input Table Name");
            DialogResult ret = dlg.ShowDialog();

            if (ret != DialogResult.OK)
            {
                return;
            }

            string tName = dlg.colName;
            string sql   = $"Create table {tName} (";

            for (int i = 0; i < dataGrid.ColumnCount; i++)
            {
                sql += $"{dataGrid.Columns[i].HeaderText} nchar(20)";
                if (i < dataGrid.ColumnCount - 1)
                {
                    sql += ", ";
                }
            }
            sql += ")";

            RunSql(sql);

            for (int i = 0; i < dataGrid.RowCount; i++)
            {
                sql = $"Insert into {tName} values (";
                for (int j = 0; j < dataGrid.ColumnCount; j++)
                {
                    string cell = (string)dataGrid.Rows[i].Cells[j].Value;
                    sql += $"'{cell}'";

                    if (j < dataGrid.ColumnCount - 1)
                    {
                        sql += ", ";
                    }
                }
                sql += ")";
                RunSql(sql);
            }
        }