示例#1
0
        public int ExecuteNonQuery(ref ClassSetupProgram setupProgram, string sSql)
        {
            int n = 0;

            try
            {
                using (MySqlConnection con = new MySqlConnection(setupProgram.connectionToDBString))
                {
                    con.Open();

                    using (MySqlCommand sqlCommand = con.CreateCommand())
                    {
                        sqlCommand.CommandText = sSql;
                        n = sqlCommand.ExecuteNonQuery();
                    }

                    con.Close();
                }
            }
            catch (Exception ex)
            {
                n = 0;
            }
            return(n);
        }
示例#2
0
        public void Execute <T>(ref ClassSetupProgram setupProgram, string sSql, ref List <T> listResult)
        {
            string result = "";

            try
            {
                string          databaseName = setupProgram.connectionToDBString;
                MySqlConnection con          = new MySqlConnection(setupProgram.connectionToDBString);
                con.Open();

                MySqlCommand    command    = new MySqlCommand(sSql, con);
                MySqlDataReader dataReader = command.ExecuteReader();

                if (dataReader.HasRows)
                {
                    while (dataReader.Read())
                    {
                        result = "";
                        for (int i = 0; i < dataReader.FieldCount; i++)
                        {
                            result += dataReader.GetString(i) + "!";
                        }
                        if (result.Count() > 2)
                        {
                            result = result.Remove(result.Count() - 1);
                        }
                        if (result != "")
                        {
                            listResult.Add(GetObject <T>(result));
                        }
                    }
                }
                con.Close();
            }
            catch (Exception ex)
            {
            }
        }