private void tsbOk_Click(object sender, EventArgs e) { if (dt.Rows.Count == 0) { DataRow row = dt.Rows.Add("table_credprogr", "table_clients", tbWhereClause.Text); } else { dt.Rows[0]["Clause"] = tbWhereClause.Text; }; TableStruct ts = new TableStruct(); ts.TableName = "where_clauses"; string[] p_keys = { "TableDBName_Left", "TableDBName_Right" }; ts.p_keys = p_keys; string[] columns = { "Clause" }; ts.columns = columns; DBFunctions.WriteToDB(dt, ts); try { DBStructure.UpdateSelectorScript(); } catch (Exception ex) { MessageBox.Show(ex.Message); } Close(); }
private void dgQuestions_CurrentCellChanged(object sender, EventArgs e) { DataRow row = GreenLight.Tools.FindCurrentRow(dgQuestions); if (splitContainer.Panel2Collapsed == false) { //Значит есть ветвление, значит надо сохранить TableStruct ts = new TableStruct(); ts.TableName = "questionary_answers"; string[] p_keys = { "question_id", "answer" }; ts.p_keys = p_keys; string[] columns = { "answer_next_question_id" }; ts.columns = columns; DBFunctions.WriteToDB(dt_answers, ts); } if ((bool)row["question_variation"] == false) { splitContainer.Panel2Collapsed = true; } else { splitContainer.Panel2Collapsed = false; LoadAnswers((int)row["question_id"]); } }
public static DataTable GetTable(string table_name, ref DataGridView dgTableData, ref TableStruct ts, int record_id = 0) { DataTable dt_table_data; DataTable dt_table_structure = DBFunctions.ReadFromDB("SELECT ColumnName,ColumnDBName,ColumnType,ColumnReference,ReferenceMultiSelect,ShowInEditor FROM tableconfig WHERE TableDBName = '" + table_name + "'"); string query_text = "SELECT table_" + table_name + ".ID"; int rows_count = 0; foreach (DataRow row in dt_table_structure.Rows) { query_text += ","; rows_count++; query_text += row["ColumnDBName"]; } query_text += " FROM table_" + table_name; if (record_id != 0) { query_text += " WHERE table_" + table_name + ".ID=" + Convert.ToString(record_id); } dt_table_data = DBFunctions.ReadFromDB(query_text); if (dgTableData != null) { dgTableData.DataSource = dt_table_data; } ts = new TableStruct(); ts.TableName = "table_" + table_name; string[] p_keys = { "ID" }; ts.p_keys = p_keys; ts.columns = new string[rows_count]; int curr_ts_row = 0; for (int i = 0; i < dt_table_structure.Rows.Count; i++) { if ((bool)dt_table_structure.Rows[i]["ShowInEditor"] == false) { dgTableData.Columns[i + 1].Visible = false; } else { dgTableData.Columns[i + 1].HeaderText = (string)dt_table_structure.Rows[i]["ColumnName"]; } /*if ( (string)dt_table_structure.Rows[i]["ColumnType"] == "Справочник") * { * dgTableData.Columns[curr_dg_column - 1].Visible = false; * dgTableData.Columns[curr_dg_column++].HeaderText = (string)dt_table_structure.Rows[i]["ColumnName"]; * }*/ //if ((bool)dt_table_structure.Rows[i]["ReferenceMultiSelect"] == false) ts.columns[curr_ts_row++] = (string)dt_table_structure.Rows[i]["ColumnDBName"]; } return(dt_table_data); }
private void FillClients() { ts = new TableStruct(); dt_clients = DBFunctions.ReadFromDB("SELECT id,CONCAT(familia_zaem,' ',IFNULL(Imya_zaem,''),' ',IFNULL(Otchestvo_zaem,'')) AS fio_zaem FROM table_clients"); dgClients.DataSource = dt_clients; dgClients.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dgClients.Columns[0].HeaderText = "ID"; dgClients.Columns[1].HeaderText = "ФИО"; }
private void SaveData() { TableStruct ts = new TableStruct(); ts.TableName = "tableconfig"; string[] p_keys = { "TableConfigID" }; ts.p_keys = p_keys; string[] columns = { "TableName", "TableDBName", "ColumnName", "ColumnDBName", "ColumnType", "ColumnReference", "ReferenceMultiSelect", "ShowInOffer", "ShowInOfferShort", "ShowInEditor", "WebOrder", "UseInWhereClause", "ShowFullName" }; ts.columns = columns; DBFunctions.WriteToDB(dt_tableconfig, ts); DBStructure.UpdateDBStructure(); }
private void SaveData() { if (!Auth.AuthModule.rights.reference_struct.write) { return; } TableStruct ts = new TableStruct(); ts.TableName = "referencesconfig"; string[] p_keys = { "ReferenceConfigID" }; ts.p_keys = p_keys; string[] columns = { "ReferenceName", "ReferenceDBName", "Hierarchycal", "ColumnName", "ColumnDBName", "ColumnType" }; ts.columns = columns; DBFunctions.WriteToDB(dt_ref_config, ts); DBStructure.UpdateDBStructure(); }
private void SaveData() { if (!Auth.AuthModule.rights.questionary_editor.write) { return; } TableStruct ts = new TableStruct(); ts.TableName = "questionary_questions"; string[] p_keys = { "question_id" }; ts.p_keys = p_keys; string[] columns = { "questionary_id", "question_text", "question_variation", "question_reference", "question_type", "question_next", "question_dest_column_db_name", "question_hint", "question_input_type", "question_web_position" }; ts.columns = columns; DBFunctions.WriteToDB(dt_questions, ts); DBStructure.UpdateDBStructure(); }
public static DataTable GetTableWODataGrid(string table_name, ref TableStruct ts, int record_id = 0) { DataTable dt_table_data; DataTable dt_table_structure = DBFunctions.ReadFromDB("SELECT ColumnName,ColumnDBName,ColumnType,ColumnReference,ReferenceMultiSelect FROM tableconfig WHERE TableDBName = '" + table_name + "'"); string query_text = "SELECT table_" + table_name + ".ID"; int rows_count = 0; foreach (DataRow row in dt_table_structure.Rows) { query_text += ","; rows_count++; query_text += row["ColumnDBName"]; } query_text += " FROM table_" + table_name; //query_text += join_text; if (record_id != 0) { query_text += " WHERE table_" + table_name + ".ID=" + Convert.ToString(record_id); } dt_table_data = DBFunctions.ReadFromDB(query_text); ts = new TableStruct(); ts.TableName = "table_" + table_name; string[] p_keys = { "ID" }; ts.p_keys = p_keys; ts.columns = new string[rows_count]; int curr_ts_row = 0; for (int i = 0; i < dt_table_structure.Rows.Count; i++) { ts.columns[curr_ts_row++] = (string)dt_table_structure.Rows[i]["ColumnDBName"]; } return(dt_table_data); }
public Questionary(int t_r_id = -1, string q_name = "Анкета клиента", int [] filt_ids = null) { InitializeComponent(); questionary_name = q_name; questionary_id = (int)DBFunctions.ReadScalarFromDB("SELECT id FROM questionary WHERE Name = '" + questionary_name + "'"); questionary_table_db_name = (string)DBFunctions.ReadScalarFromDB("SELECT TableDBName FROM questionary WHERE Name = '" + questionary_name + "'"); current_question_id = (int)DBFunctions.ReadScalarFromDB("SELECT first_question_id FROM questionary WHERE Name = '" + questionary_name + "'"); questionary_use_filter = (bool)DBFunctions.ReadScalarFromDB("SELECT use_filter FROM questionary WHERE Name = '" + questionary_name + "'"); if (questionary_use_filter) { filter_ids = (int[])filt_ids.Clone(); string query_text = "SELECT DISTINCT question_id FROM questionary_filter WHERE questionary_id=@q_id AND filter_id IN ("; foreach (int filter_id in filter_ids) { query_text += filter_id.ToString() + ","; } query_text = query_text.TrimEnd(',') + ")"; Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("q_id", questionary_id); dt_filter_allowed_questions = DBFunctions.ReadFromDB(query_text, parameters); //Дойдем до первого разрешенного вопроса while (current_question_id != -1) { if (dt_filter_allowed_questions.Select("question_id = " + Convert.ToString(current_question_id)).Length > 0) { break; } parameters = new Dictionary <string, object>(); parameters.Add("questionary_id", questionary_id); parameters.Add("q_id", current_question_id); object new_question_id = DBFunctions.ReadScalarFromDB("SELECT question_next FROM questionary_questions WHERE questionary_id=@questionary_id AND question_id = @q_id", parameters); if (new_question_id == DBNull.Value) { current_question_id = -1; } else { current_question_id = (int)new_question_id; } } } question_history = new List <QuestionInfo>(); table_record_id = t_r_id; //Подгрузим инфо о записи таблицы или пустую строку ts = new TableStruct(); dt_table_data = Tables.GetTableWODataGrid(questionary_table_db_name, ref ts, table_record_id); if (dt_table_data.Rows.Count > 0) { row_table_record = dt_table_data.Rows[0]; } else { row_table_record = dt_table_data.NewRow(); dt_table_data.Rows.Add(row_table_record); } }
static void UpdateMainTableStructure(string TableDBName) { //Получим требуемую структуру DataTable neededStructure = DBFunctions.ReadFromDB("SELECT TableConfigID,ColumnDBName,ColumnDBName_Old,ColumnType,ReferenceMultiSelect FROM tableconfig WHERE TableDBName = '" + TableDBName + "'"); //Получим текущую структуру DataTable CurrentStrurture = new DataTable(); bool new_table = false; try { CurrentStrurture = DBFunctions.ReadFromDB("SHOW COLUMNS FROM table_" + TableDBName); } catch (Exception) { //Таблицы не существует, будем создавать new_table = true; } if (new_table) { string CommandText = "CREATE TABLE `table_" + TableDBName + "` ("; //ПК CommandText += "`ID` int(11) NOT NULL AUTO_INCREMENT"; foreach (DataRow row in neededStructure.Rows) { if ((string)row["ColumnType"] == "Справочник" && (bool)row["ReferenceMultiSelect"] == true) { CommandText += ",`" + row["ColumnDBName"] + "` MEDIUMTEXT DEFAULT NULL"; //CreateMultiRefTable(TableDBName, (string)row["ColumnDBName"]); } { string field_type = ConvertTypeToSQL((string)row["ColumnType"]); if (field_type != null) { CommandText += ",`" + row["ColumnDBName"] + "` " + field_type + " DEFAULT NULL"; } } } CommandText += ", PRIMARY KEY (`ID`)) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8"; DBFunctions.ExecuteCommand(CommandText); } else { //Создаем и меняем строки foreach (DataRow row in neededStructure.Rows) { string col_type; if ((string)row["ColumnType"] == "Справочник" && (bool)row["ReferenceMultiSelect"] == true) { //CreateMultiRefTable(TableDBName, (string)row["ColumnDBName"]); col_type = "MEDIUMTEXT"; } else { col_type = ConvertTypeToSQL((string)row["ColumnType"]); } { //Ищем колонку DataRow[] foundRows = CurrentStrurture.Select("Field = '" + row["ColumnDBName_Old"] + "'"); if (foundRows.Length == 0) { //Добавляем колонку DBFunctions.ExecuteCommand("ALTER TABLE table_" + TableDBName + " ADD `" + row["ColumnDBName"] + "` " + col_type); } else { //Проверяем соответствие имени if ((string)foundRows[0]["Field"] != (string)row["ColumnDBName"]) { //Переименовываем колонку try { DBFunctions.ExecuteCommand("ALTER TABLE `table_" + TableDBName + "` CHANGE `" + row["ColumnDBName_Old"] + "` `" + row["ColumnDBName"] + "` " + col_type); row["ColumnDBName_Old"] = row["ColumnDBName"]; } catch (Exception) { System.Windows.Forms.MessageBox.Show("Невозможно изменить тип столбца.", "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } } else if ((string)foundRows[0]["Type"] != col_type) { //Меняем тип try { DBFunctions.ExecuteCommand("ALTER TABLE `table_" + TableDBName + "` MODIFY `" + row["ColumnDBName"] + "` " + col_type); } catch (Exception) { System.Windows.Forms.MessageBox.Show("Невозможно изменить тип столбца.", "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } } } } } //Внесем изменения конфигурационную таблицу if (neededStructure.GetChanges() != null) { TableStruct ts = new TableStruct(); ts.TableName = "tableconfig"; string[] p_keys = { "TableConfigID" }; ts.p_keys = p_keys; string[] columns = { "ColumnDBName_Old" }; ts.columns = columns; DBFunctions.WriteToDB(neededStructure, ts); } //Удалим лишние колонки foreach (DataRow row in CurrentStrurture.Rows) { if ((string)row["Field"] == "ID") { continue; } DataRow[] foundRows = neededStructure.Select("ColumnDBName = '" + row["Field"] + "'"); if (foundRows.Length == 0) { //Удаляем колонку DBFunctions.ExecuteCommand("ALTER TABLE table_" + TableDBName + " DROP `" + row["Field"] + "`"); } } //Удалим лишние таблицы с множественным выбором //DataTable multi_ref_tables = DBFunctions.ReadFromDB("SHOW TABLES WHERE tables_in_" + DBFunctions.db_name + " LIKE 'MultiRef_" + TableDBName + "_%'"); //foreach(DataRow row in multi_ref_tables.Rows) //{ // DataRow[] foundRows = neededStructure.Select("'MultiRef_" + TableDBName + "_' + ColumnDBName = '" + row["tables_in_" + DBFunctions.db_name] + "' AND ReferenceMultiSelect = 1"); /* if (foundRows.Length == 0) * { * //Удаляем таблицу * DBFunctions.ExecuteCommand("DROP TABLE `" + row["tables_in_" + DBFunctions.db_name] + "`"); * * } * }*/ } }
static void UpdateReferenceStructure(string ref_db_name) { //Получим требуемую структуру DataTable neededStructure = DBFunctions.ReadFromDB("SELECT * FROM referencesconfig WHERE ReferenceDBName = '" + ref_db_name + "'"); if (neededStructure.Rows.Count == 0) { System.Windows.Forms.MessageBox.Show("Неверное наименование справочника.", "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } bool hierarchical = Convert.ToBoolean(neededStructure.Rows[0]["Hierarchycal"]); //Проверим есть ли такая таблица в БД bool ref_data_exists = Convert.ToBoolean(DBFunctions.ReadFromDB("Show tables like 'ref_data_" + ref_db_name + "'").Rows.Count); bool ref_hierarchy_exists = Convert.ToBoolean(DBFunctions.ReadFromDB("Show tables like 'ref_hierarchy_" + ref_db_name + "'").Rows.Count); if ((hierarchical && ref_data_exists && ref_hierarchy_exists) || //Иерархический, есть обе таблицы (!hierarchical && ref_data_exists && !ref_hierarchy_exists) //Не иерархический, есть одна таблица ) { //Всё ок, проверим соответствие состава колонок DataTable CurrentStrurture = DBFunctions.ReadFromDB("SHOW COLUMNS FROM ref_data_" + ref_db_name); //Создаем и меняем строки foreach (DataRow row in neededStructure.Rows) { //Ищем колонку DataRow[] foundRows = CurrentStrurture.Select("Field = '" + row["ColumnDBName_Old"] + "'"); if (foundRows.Length == 0) { //Добавляем колонку DBFunctions.ExecuteCommand("ALTER TABLE ref_data_" + ref_db_name + " ADD `" + row["ColumnDBName"] + "` " + ConvertTypeToSQL((string)row["ColumnType"])); } else { //Проверяем соответствие имени if ((string)foundRows[0]["Field"] != (string)row["ColumnDBName"]) { //Переименовываем колонку try { DBFunctions.ExecuteCommand("ALTER TABLE `ref_data_" + ref_db_name + "` CHANGE `" + row["ColumnDBName_Old"] + "` `" + row["ColumnDBName"] + "` " + ConvertTypeToSQL((string)row["ColumnType"])); row["ColumnDBName_Old"] = row["ColumnDBName"]; } catch (Exception) { System.Windows.Forms.MessageBox.Show("Невозможно изменить тип столбца.", "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } } else if ((string)foundRows[0]["Type"] != ConvertTypeToSQL((string)row["ColumnType"])) { //Меняем тип try { DBFunctions.ExecuteCommand("ALTER TABLE `ref_data_" + ref_db_name + "` MODIFY `" + row["ColumnDBName"] + "` " + ConvertTypeToSQL((string)row["ColumnType"])); } catch (Exception) { System.Windows.Forms.MessageBox.Show("Невозможно изменить тип столбца.", "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } } } } //Внесем изменения конфигурационную таблицу if (neededStructure.GetChanges() != null) { TableStruct ts = new TableStruct(); ts.TableName = "referencesconfig"; string[] p_keys = { "ReferenceConfigID" }; ts.p_keys = p_keys; string[] columns = { "ColumnDBName_Old" }; ts.columns = columns; DBFunctions.WriteToDB(neededStructure, ts); } //Удалим лишние колонки foreach (DataRow row in CurrentStrurture.Rows) { if ((string)row["Field"] == "id" || (string)row["Field"] == "ID") { continue; } if ((string)row["Field"] == "parentid" || (string)row["Field"] == "ParentID") { continue; } DataRow[] foundRows = neededStructure.Select("ColumnDBName = '" + row["Field"] + "'"); if (foundRows.Length == 0) { //Удаляем колонку DBFunctions.ExecuteCommand("ALTER TABLE ref_data_" + ref_db_name + " DROP `" + row["Field"] + "`"); } } //Создадим хранимые процедуры и триггеры string ref_create_script = (string)DBFunctions.ReadScalarFromDB("SELECT script FROM scripts WHERE script_name = 'Reference_Create'"); ref_create_script = ref_create_script.Replace("[RefDBName]", ref_db_name); DBFunctions.ExecuteScript(ref_create_script); return; } if (ref_data_exists || ref_hierarchy_exists) { if (System.Windows.Forms.MessageBox.Show("Сменился тип справочника " + ref_db_name + " данные справочника будут удалены. Продолжить?", "Вопрос", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No) { return; } } //Удалим таблицы if (ref_data_exists) { DBFunctions.ExecuteCommand("DROP TABLE `ref_data_" + ref_db_name + "`"); } if (ref_hierarchy_exists) { DBFunctions.ExecuteCommand("DROP TABLE `ref_hierarchy_" + ref_db_name + "`"); } //Создадим новые таблицы //Таблица с данными string CommandText = "CREATE TABLE `ref_data_" + ref_db_name + "` ("; CommandText += "`ID` int(11) NOT NULL AUTO_INCREMENT"; CommandText += ",`ParentID` int(11) DEFAULT 0"; foreach (DataRow row in neededStructure.Rows) { if (row["ColumnType"] == System.DBNull.Value) { continue; } string field_type = ConvertTypeToSQL((string)row["ColumnType"]); if (field_type != null) { CommandText += ",`" + row["ColumnDBName"] + "` " + field_type + " DEFAULT NULL"; } } CommandText += ", PRIMARY KEY (`ID`)) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8"; DBFunctions.ExecuteCommand(CommandText); //Таблица с иерархией if (hierarchical) { CommandText = "CREATE TABLE `ref_hierarchy_" + ref_db_name + "` ("; CommandText += "`ElemID` int(11) NOT NULL"; CommandText += ",`ParentID` int(11) NOT NULL"; CommandText += ",`Level` int(11) NOT NULL"; CommandText += ", PRIMARY KEY (`ElemID`,`ParentID`,`Level`)) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8"; DBFunctions.ExecuteCommand(CommandText); } //Создадим хранимые процедуры и триггеры string ref_create_script_inner = (string)DBFunctions.ReadScalarFromDB("SELECT script FROM scripts WHERE script_name = 'Reference_Create'"); ref_create_script_inner = ref_create_script_inner.Replace("[RefDBName]", ref_db_name); DBFunctions.ExecuteScript(ref_create_script_inner); }
private void CreateEditControls() { splitContainer.Panel2.Controls.Clear(); edit_controls = new Dictionary <string, Control>(); ref_table_struct = new TableStruct(); DataTable dt_ref_columns = DBFunctions.ReadFromDB("SELECT ColumnName,ColumnDBName,ColumnType FROM referencesconfig WHERE ReferenceDBName = '" + reference_db_name + "'"); DataRow id_row = dt_ref_columns.NewRow(); id_row["ColumnName"] = "Код"; id_row["ColumnDBName"] = "ID"; id_row["ColumnType"] = "Строка50"; dt_ref_columns.Rows.InsertAt(id_row, 0); ref_table_struct.TableName = "ref_data_" + reference_db_name; string[] p_keys = { "ID" }; ref_table_struct.p_keys = p_keys; ref_table_struct.columns = new string[dt_ref_columns.Rows.Count]; ref_table_struct.columns[dt_ref_columns.Rows.Count - 1] = "ParentID"; foreach (DataRow column_row in dt_ref_columns.Rows) { if (column_row["ColumnName"] == DBNull.Value) { column_row["ColumnName"] = "Наименование"; column_row["ColumnDBName"] = "RefName"; } Label new_label = new Label(); new_label.Text = (string)column_row["ColumnName"]; new_label.Left = 10; new_label.Height = 20; new_label.Top = 12 + Convert.ToInt32(edit_controls.Count / 2) * (new_label.Height + 5); edit_controls.Add("label_" + column_row["ColumnDBName"], new_label); splitContainer.Panel2.Controls.Add(edit_controls["label_" + column_row["ColumnDBName"]]); TextBox new_tb = new TextBox(); new_tb.Tag = (string)column_row["ColumnDBName"]; new_tb.Left = 150; new_tb.Top = 10 + Convert.ToInt32(edit_controls.Count / 2) * (new_tb.Height + 5); new_tb.Width = splitContainer.Panel2.Width - 160; if (select_mode) { new_tb.ReadOnly = true; } if ((string)new_tb.Tag == "ID") { new_tb.ReadOnly = true; } else { ref_table_struct.columns[dt_ref_columns.Rows.IndexOf(column_row) - 1] = (string)column_row["ColumnDBName"]; //Проверим право на запись new_tb.ReadOnly = !Auth.AuthModule.rights.references.write; } edit_controls.Add((string)column_row["ColumnDBName"], new_tb); splitContainer.Panel2.Controls.Add(edit_controls[(string)column_row["ColumnDBName"]]); } }
public static void WriteToDB(DataTable dt, TableStruct table_struct) { MySqlConnection connection = Connect(); MySqlDataAdapter data_adapter = new MySqlDataAdapter("", connection); data_adapter.DeleteCommand = new MySqlCommand("", connection); string DeleteCommandText = "DELETE FROM " + table_struct.TableName /*.ToLower()*/ + " WHERE"; foreach (string pk in table_struct.p_keys) { DeleteCommandText += " " + pk + " = @" + pk; data_adapter.DeleteCommand.Parameters.Add("@" + pk, ColumnType(dt.Columns[pk]), 50, pk); if (table_struct.p_keys[table_struct.p_keys.Length - 1] != pk) { DeleteCommandText += " AND"; } } ; data_adapter.DeleteCommand.CommandText = DeleteCommandText; data_adapter.UpdateCommand = new MySqlCommand("", connection); string UpdateCommandText = "UPDATE " + table_struct.TableName /*.ToLower()*/ + " SET"; foreach (string column in table_struct.columns) { UpdateCommandText += " " + column + " = @" + column; data_adapter.UpdateCommand.Parameters.Add("@" + column, ColumnType(dt.Columns[column]), 50, column); if (table_struct.columns[table_struct.columns.Length - 1] != column) { UpdateCommandText += ", "; } } ; UpdateCommandText += " WHERE"; foreach (string pk in table_struct.p_keys) { UpdateCommandText += " " + pk + " = @" + pk; data_adapter.UpdateCommand.Parameters.Add("@" + pk, ColumnType(dt.Columns[pk]), 50, pk); if (table_struct.p_keys[table_struct.p_keys.Length - 1] != pk) { UpdateCommandText += " AND"; } } ; data_adapter.UpdateCommand.CommandText = UpdateCommandText; data_adapter.InsertCommand = new MySqlCommand("", connection); string InsertCommandText = "INSERT INTO " + table_struct.TableName /*.ToLower()*/ + " SET"; foreach (string column in table_struct.columns) { InsertCommandText += " " + column + " = @" + column; data_adapter.InsertCommand.Parameters.Add("@" + column, ColumnType(dt.Columns[column]), 50, column); InsertCommandText += ", "; } ; foreach (string pk in table_struct.p_keys) { InsertCommandText += " " + pk + " = @" + pk; data_adapter.InsertCommand.Parameters.Add("@" + pk, ColumnType(dt.Columns[pk]), 50, pk); if (table_struct.p_keys[table_struct.p_keys.Length - 1] != pk) { InsertCommandText += ", "; } } ; data_adapter.InsertCommand.CommandText = InsertCommandText; data_adapter.Update(dt); dt.AcceptChanges(); Disconnect(connection); }