Пример #1
0
            public static MySQLResult sql_query_local(string query)
            {
                {
                    var result = new MySQLResult {
                        count_rows = 0
                    };
                    // Выполняем запрос.
                    var dataSet = new DataSet();
                    //string connectionString = System.Configuration.ConfigurationSettings.AppSettings["MyConnection"];
                    string connectionString = ConnectionStringLocal;
                    using (var connection = new SqlConnection(connectionString))
                    {
                        try
                        {
                            connection.Open();
                            var dbAdapter = new SqlDataAdapter(query, connection);
                            dbAdapter.Fill(dataSet);
                            connection.Close();
                        }
                        catch (Exception ex)
                        {
                            if (connection.State == ConnectionState.Open)
                            {
                                connection.Close();
                            }
                        }
                    }

                    // Заполняем данные.
                    if (dataSet.Tables.Count == 0)
                    {
                        return(result);
                    }
                    var table = dataSet.Tables[0];
                    // Собираем имена.
                    for (var columnIndex = 0; columnIndex < table.Columns.Count; columnIndex++)
                    {
                        result.columns.Add(table.Columns[columnIndex].ColumnName);
                    }
                    // Собираем данные.
                    for (var rowIndex = 0; rowIndex < table.Rows.Count; rowIndex++)
                    {
                        var row    = table.Rows[rowIndex];
                        var newRow = new MySQLRow();
                        for (var columnIndex = 0; columnIndex < result.columns.Count; columnIndex++)
                        {
                            newRow.values.Add(row[columnIndex].ToString());
                        }
                        result.rows.Add(newRow);
                        result.count_rows++;
                    }
                    return(result);
                }
            }
 public void AddMySQLRow(MySQLRow row) {
     this.Rows.Add(row);
 }
 public void RemoveMySQLRow(MySQLRow row) {
     this.Rows.Remove(row);
 }
 public MySQLRowChangeEvent(MySQLRow row, global::System.Data.DataRowAction action) {
     this.eventRow = row;
     this.eventAction = action;
 }