static string dataConnection = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; static IDbConnection connection = new MySqlConnection(dataConnection); public static string GetCode() { using (connection) { //查询 string code = connection.Query($"SELECT orignal_code FROM `pack_code_oc` ").FirstOrDefault(); //删除 connection.Execute($"delete FROM `pack_code_oc` where orignal_code='{ code}'"); return code; } }