Пример #1
0
        protected ModelResult QueryStmt(string query, params string [] values)
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.Connection  = connect;
            cmd.CommandText = query;
            cmd.Prepare();
            for (int i = 0; i < values.Length; i++)
            {
                cmd.Parameters.AddWithValue("@" + i.ToString(), values[i]);
            }
            var reader = cmd.ExecuteReader();
            var result = new ModelResult();

            while (reader.Read())
            {
                var sub_result = new Dictionary <string, string>();
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    sub_result[reader.GetName(i)] = reader.GetString(i);
                }
                result.Add(sub_result);
            }
            reader.Close();
            result.InsertID = cmd.LastInsertedId;

            return(result);
        }
Пример #2
0
        protected ModelResult Query(string query)
        {
            MySqlCommand cmd = new MySqlCommand();

            cmd.Connection  = connect;
            cmd.CommandText = query;
            var reader = cmd.ExecuteReader();
            var result = new ModelResult();

            while (reader.Read())
            {
                var sub_result = new Dictionary <string, string>();
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    sub_result[reader.GetName(i)] = reader.GetValue(i).ToString();
                }
                result.Add(sub_result);
            }
            reader.Close();

            result.InsertID = cmd.LastInsertedId;
            return(result);
        }